- Home /
Instances not destroyed when editor is stopped
HI,
I have a NPCSquad class that is derived from a Squad class and ultimately a MonoBehaviour. The class contains a static method to create an instance of the game object with the script attached and some soldiers to populate the squad held in an ArrayList.
All works well until I stop the game in the editor when I am left with the NPCSquad and all it's soldiers as part of the scene. When I have done this sort of thing before the instances have disappeared when leaving play mode.
Any ideas? Is there anything I should be looking out for in my scripts that might cause this?
Answer by Glurth · Jan 31, 2018 at 11:24 AM
[ExecuteInEditMode] If your static function is being called, in the editor, right after the scene reloads (what happens when you stop play), this would put those objects into the freshly loaded scene, without the need to hit play.
This was the solution. I had called the static create method from an initialiser in a script from an asset I bought not noticing the [ExecuteInEdit$$anonymous$$ode] ath the top of the code.
Thanks.
Great! glad you got it working. Please "accept" the answer.
Your answer
Follow this Question
Related Questions
Add gameObject/transform to script component slot with editor 1 Answer
Adding to GameObject context menu WITHOUT [MenuItem(...)] 1 Answer
Make GameObject Independent of Editer Physics 1 Answer
How to prevent a script on a disabled object from firing? 0 Answers
How to access a game object from a different scene? 0 Answers