[Solved]Destroy instantiated objects in editor

Every time I finnish a simulation (using the Play button) in the editor, the instantiated objects remains. So if I want to test it on the device, I have to manually clean them up, otherwise these objects are built into the application (because they are in the hierarchy).

Just wondering if anyone has a simple way of cleaning up the editor?

Simple actually,

Just have a script attached to your instantiated object that will destroy it after its been used. you can use a timer, or some sort of boolean to determine when to clean up

you should check into the script reference for: Destroy(gameObject);

Thanks for the reply :lol:
My problem is when to destroy them, since there is no event for an “editor stop” (or is there?), and Destroy/DestroyImmediate doesn’t seem to destroy them immediately.

This behavior is weird if I understood you right.

Do you have a small project we can check?

I’ve actually created a bug report quite some time ago, shortly after the 1.5 release. Case 283501

I have figured it out while making the test project to upload lol

It’s all because of this:

[ExecuteInEditMode()]

Once I commented this out everything works perfect!

Cheers :lol:

Without that, it won’t do anything in the editor itself. it will only run in the game mode, not the editor mode :slight_smile:

if that is what you wanted, its naturally fine.
But its still very annoying that the destroys don’t work for editor executed scripts (I’ve struggled over it when letting SpriteManager create its sprites in the editor mode so I get visual response for the GO placements)

Right, this is how ExecuteInEditMode() does work. I doubt we can change a lot there.