Page MenuHome

Drivers that use modified namespaces only work after reloading twice blender files with the same internal script
Closed, ResolvedPublic

Description

Operating system: Ubuntu 18.04.1
Graphics card: RX 480

Blender Version
Broken:
blender-2.80-3730d16347a5-2019-03-04, 16:04
Worked:
Open the file twice

Short description of error
Drivers that use modified namespaces only work after reloading twice blender files with the same internal script.

Exact steps for others to reproduce the error
I made an empty with saturation and hue object properties, these properties are later plugged into a light's RGB values using drivers, (in this case, for cycles and eevee), for this purpose a script is used that adds an entry to the driver's namespace to convert hue and saturation into RGB. I make sure this script is registered and that blender auto-runs python files.

Event Timeline

Jacques Lucke (JacquesLucke) lowered the priority of this task from Needs Triage by Developer to Needs Information from User.Mar 5 2019, 11:05 AM

I don't know what to do in this file exactly to see the issue.
Can you create an even simpler example? Maybe just a simple driver on the object location?

I tried to make it as simply as possible, 3 drivers controlling the RGB channels of one light, with 2 properties in one empty and one script appending a function to the namespace, also appended a video.


Jacques Lucke (JacquesLucke) raised the priority of this task from Needs Information from User to Confirmed, Medium.Mar 5 2019, 5:45 PM

The problem is that the depsgraph is build before your script executes. Both happens in wm_file_read_post, but in the "wrong" order.

I'm not aware of any non-hacky solution to solve this currently.
The cleanest solution would probably be to make the Register option for text blocks a bit more advanced. For example, allowing to run the script before or after depsgraph evaluation. Even more options like running a script on frame change etc. could be possible. All the event handlers we have basically.

@Brecht Van Lommel (brecht), can you think of a case when it is useful to run the script after the depsgraph has been build? Setting up e.g. driver namespaces seems to be one of the most important use cases for this auto-run feature.