Invoking events on specific gameobjects after loading scene

Let’s say that I enter Scene_A, on which there are two enemies, enemy_1, and enemy_2, I destroy enemy_1 and leave Scene_A. After loading Scene_B and messing around for 10 minutes I want to go back to Scene_A. Now when I enter Scene_A there are two enemies again, but I have killed enemy_1 in the past.

How should I go about destroying this enemy? There are no unique ids in Unity (well, there is InstanceID, but it’s generated per instance, so after each load of Scene_A every enemy would have different id) so I’m not sure how can I keep track of objects that should be destroyed immediately after loading new scene. I could generate them manually (bleh) but I use prefabs quite often and if I would click “Apply” button on one instance of my prefab then all ids would get overwritten.

You’ll want to look into saving the state of the scene. Many ways to go about it.
http://lmgtfy.com/?q=unity+save+scene+state

1 Like