- Home /
Function that starts on game startup but doesn't update on scene change.
Is it possible to have a function that doesn't restart when scenes are changed and just starts once when the game is opened? I tried using Start() and Awake() but they update every time the scene is loaded.
Answer by MartinIsla · Feb 05, 2019 at 04:09 AM
Sure thing, just add DontDestroyOnLoad(gameObject) to the Awake() of the method you want to keep.
Keep in mind this will not destroy the script in other scenes, so you could end up with unwanted duplicates. To avoid that while keeping development simple, I use a singleton.
Answer by unity_0sdsWZad6Fwp-A · Feb 06, 2019 at 10:39 PM
Thank you, I added this to a timer script I had made. Now that I have this It fixed my co-routine and everything is working now.
Your answer
Follow this Question
Related Questions
Rotation script working only in one instance 1 Answer
Open Door Once But Sound Plays again when i trigger at the door 3 Answers
how to make collision istrigger and play once on collision 1 Answer
+= sign not working properly unity 1 Answer
SceneManager.GetAllScenes() only returns the current scene 3 Answers