- Home /
The question is answered, right answer was accepted
Script being called without being in scene?
(sorry for the formatting of this post; I can't seem to add spaces between the paragraphs)
In my game, there is a script being called when it is not in the current scene. The Start(() method is being called despite it not being attached to any component in the scene (I have confirmed this by putting a Debug.Log statement in the method and also searching the Hierarchy for objects containing the script). The script claims to be attached to the Main Camera, however it is not (checked both visually in the Inspector and by searching the Hierarchy).
How is this possible?
Just to pre-empt some suggestions:
1) I am not using [ExecuteInEditMode].
2) This is seen in both Play mode and the built game.
3) I have one object that is DontDestroyOnLoad(), however the script is not attached to that object.
Some further info: the script is attached to the Main Camera in the scene that precedes the current scene (I have a loading scene followed by the gameplay scene), but my understanding is that changing the scene should completely destroy everything the older scene.
I see this in both Unity 2018.2.18 and 2018.3.3.
If you upload a repro project I'll take a look at it. If you do, please use Unity 2018.2.18, which I have installed.
Thanks for the offer however, as noted below, I'm an idiot and have now identified the cause. Thanks again.
I'm glad you fixed it. Don't beat yourself up, we all make mistakes from time to time.
Answer by oclipa · Feb 03, 2019 at 10:36 AM
Aah! I'm an idiot; I just discovered the problem (a command that was reloading the loading scene).
Please ignore...