Cleaning up objects that spawn other objects when destroyed?

So I have some objects that are designed to create other objects when you destroy them. Like boxes you break open and there are items inside. Bombs that blow up and then spawn an explosion.

I thought everything was working fine, but now I see I have a problem when I try to change scenes, heck, even when I stop the play-in-editor I wind up spawning extra objects that then throw an error into the console.

So I’m wondering: is there a smarter way to go about this? How do I have objects that spawn things when they get destroyed, but not when they get destroyed because the scene is ending?

dont use ondestroy do if hp <= 0 then spawn things and destory

1 Like

Or have an explicit interface (IOnDestroy) that you check for and call for anything that should have actual gameplay ‘on destroy’ effects.