# How to receive a msgbus notification when an object is added to or removed from the scene?

I could track the object count in a variable and compare it to the size of bpy.context.scene.objects in a draw call, or similarly track the collection keys, but that feels imprecise and perhaps prone to sync issues. I'd much prefer to subscribe to something through msgbus and receive a notification when the size of the object collection changes, for example. But what to subscribe to? I managed to kill Blender a few times while experimenting with various things but so far have come up blank. My best guess is the size of a collection is computed rather than a stored property with RNA that can be used with msgbus, but I'd appreciate knowing for sure. Any smart folks out there who've been msgbus wrangling, I'd sure appreciate any advice, even if it's just to confirm that this is a silly idea. Thanks for your brain rental!

• Dec 4 '20 at 12:51
• @batFINGER are you... are you God? XD Thanks a million for your input, my friend, much appreciated. I'll read this then go poke Blender with a stick again. Dec 4 '20 at 12:57
• @batFINGER The example you've given works for adding objects but not deletion, where the active object property does not change. I don't suppose it's possible to add msgbus hooks for bpy.ops? Dec 4 '20 at 13:45
• It does change to None after the delete operator, however is not picked up by msgbus. An idea would be to make a pointer property to the prior selection, which if None on the next selection indicates it was removed. Dec 4 '20 at 14:27