In Blender 2.8x the undo/redo operation system (ctrl+z / ctrl+shift+z) has been completely rebuilt. One of the results of this API change is when the undo operation is performed, all objects in the scene are fully recreated – the current object is destroyed, and a completely new object is created instead. Pointers to the old objects (before the undo operation) now point to invalid objects that can no longer be used.
The official Blender Python API documentation describes this behavior.
You can check this by executing the simple code in the Blender Python Console:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
obj = bpy.context.active_object print(obj) # <bpy_struct, Object("Suzanne")> # make some actions, for example, move the object # g - z - 1 - enter # make undo # ctrl+z print(obj) # <bpy_struct, Object invalid> |
Object lists also broke with undo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
lst = bpy.context.selected_objects[:] print(last) # [bpy.data.objects['Suzanne'], bpy.data.objects['Cube']] print(bpy.context.active_object) # bpy.data.objects['Suzanne'] bpy.context.active_object in lst # True # make any action and undo it print(lst) # [<bpy_struct, Object invalid>, <bpy_struct, Object invalid>] print(bpy.context.active_object) # bpy.data.objects['Suzanne'] bpy.context.active_object in lst # False |
What does all of this turn into practice?
Beware of using long-time living object pointers and object lists in your code. If the user has the ability to press ctrl+z during the lifetime of such a link or list – they will become broken!