Skip to content

Spawned Object Tracking

Try a coin, a bullet, a row of crates. When you Stop, or press Run again, the objects that script created are cleared with it. The scene stays the scene you started with, ready for the next try.

This is on by default.

ZenCoder → Preferences → General → Track Spawned Objects

1.2.0 · Shoshin

Introduced in the v1.2.0 release.

Spawn, then start clean

public GameObject coin;

public void Start()
{
    for (int i = 0; i < 8; i++)
        Instantiate(coin, transform.position + Vector3.right * i, Quaternion.identity);
}

Press Run. Eight coins appear. Press Stop. They are gone.

Change the spacing and press Run again. The previous coins are removed first, then the new ones appear.

The same cleanup applies however you call Instantiate: on its own, with a parent, or with a position and rotation. A spawned component removes its whole object, so the hierarchy is left without an empty duplicate.

Destroy one yourself

GameObject dropped = Instantiate(coin, transform.position, Quaternion.identity);
Destroy(dropped, 1.5f);

That coin is yours. After you destroy it, ZenCoder leaves it alone. Anything still alive when you Stop or Run again is cleared with the rest.

Leave them in the scene

Turn Track Spawned Objects off.

Instantiate then behaves like it does on any other component. The objects stay until the script destroys them, or until you leave Play Mode.


← Safe Execution Syntax Palette →