Objects referring in a depsgrapth_update handler feature

When using the “depsgraph_update” handler, making actions with objects passed to the handler does not give the full result. For example, properties of an object referring to it through the “object.id”, could be not completely changed.

Let’s define the “depsgraph_update_post” handler, inside which we will change some object’s property, for example, the viewport color of the object.

After registering the handler let’s make any changes in the current mesh (to execute the handler).

In this example, to change the color of an object, we referred to it through the “object.id”:

As we can see, the color of the object in the viewport changes, but the color in the parameter on the object properties panel  – doesn’t. After unregistering our handler, when the mesh changes, its color is restored with the original color from the parameter.

To avoid this behavior, it is better to refer to the object by name through the “bpy.data.objects” list.

The same handler, with accessing an object through the “bpy.data.objects”, changes the color of the object completely both in the viewport and in the parameter:


*.blend file with the example code for my Patreon subscribers.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comment
Inline Feedbacks
View all comments