Since the Python API does not support events when objects are removed I had to go a pretty "uncomfortable" way to visualize contents of a game level to which I write an addon.
The game places different stuff in a level, and in Blender, I represent that stuff with Empty's. Each Empty has children mesh objects attached to it holding the model(s) to visualize that stuff (e.g. an item box, coin, banana with sunglasses or whatever crazy ideas the lead designers get).
Now, whenever someone deletes the Empty, I also want to delete all the children. Since Blender does not delete children automatically when the parent is killed, I check for "lose" children in
scene_update_post. (I also do it the other way round: If an Empty has no children, I add the models to it).
This worked fine on a i7 6700K fullblown atomic power plant until I tested it on a 5 year old PC with an AMD Athlon 6000+ CPU. Blender uses one whole core all the time, so I cut down the code I do in
scene_update_post to see what's causing this performance rape. Already these few lines make Blender use 24% of the core, when there are like 100 objects in the scene:
@bpy.app.handlers.persistent def scene_update_post(scene): for ob in scene.objects: hl3 = ob.halflife3_props # Yes, this name is made up
That's quite horrible. But I don't know any other way to check for objects which just lost their parent. It would be even more horrible to tell the level designers (which are not the biggest Blender boys) to select all children first and then delete them with the parent.
Are there better solutions to solve this problem? I thought about overriding the deletion behavior for objects of a specific type string I stored in my custom properties, but I have no clue if that's even possible.