I wrote a script that creates a custom property in the World panel. It then creates a driver on the object color that's driven by this custom property, but it doesn't recognize the data path as valid until I interact with the custom property slider in the viewport.

I have tried code to redraw all UI panels, among other things. Clicking the "update dependencies" button doesn't work. Nothing seems to make the custom property accessible/visible to Blender except interacting with it and then clicking in the driver so the data path is magically recognized as valid.

I need the custom property to exist on the World panel in the UI, with the slider, exactly as shown. I realize there are other ways to create custom properties, but I need this specific result for my workflow.

The problem:

enter image description here

My code:

import bpy

context = bpy.context

# Create new custom prop 
new_custom_prop = "test_prop"


my_world = context.scene.world
id_props = context.scene.world.id_properties_ui(new_custom_prop)

obj = context.active_object

# Add drivers to object color
d = obj.driver_add('color',0)
d.driver.type = "AVERAGE"

var1 = d.driver.variables.new()
var1.targets[0].id_type = 'WORLD'
var1.targets[0].id = context.scene.world
var1.targets[0].data_path = "[\""+new_custom_prop+"\"]"
  • $\begingroup$ That is because setting the relative data path ["test_prop"] via script causes blender to only search the custom properties on your cube object but since your cube has no custom properties it displays in red as error. You would have to input the full data path bpy.context.scene.world["test_prop"] but it's not supported. It looks like the path field in the driver editor only accepts relative paths but for some reason, if you manually input the relative path ["test_prop"] it searches the world's custom properties as well if it does not find any custom properties on the cube object. $\endgroup$ Dec 23, 2022 at 0:43
  • $\begingroup$ maybe this is a bug because why would it work the manual way but not via script $\endgroup$ Dec 23, 2022 at 1:15
  • 1
    $\begingroup$ @HarryMcKenzie I found this issue in Blender developer bug tracker, developer.blender.org/T74000, and developer.blender.org/T63793 $\endgroup$
    – JakeONeal
    Dec 28, 2022 at 19:49


Browse other questions tagged .