So I have a persistent game manager which exists in the first scene and stays throughout the scenes with DontDestroyOnLoad(); What I want to do is when a level loads I want to find certain UI elements with GameObject.Find() and update those according to player health… etc. I have an OnSceneLoad function similar to this Unity - Scripting API: SceneManagement.SceneManager.sceneLoaded in Awake(). However, when I search for the object, for one frame, it displays an error that the object is not found. How do I make my script wait until the level is done loading then find objects()?
You are probably looking for SceneManager.LoadSceneAsync.
1 Like
Why you don’t use Awake() in the UI elements?
I would put a script in the UI canvas with references to the child elements that need to be updated, and in the Awake() I would communicate with the GameManager so as to ask for the values.
This way you also avoid GameObject.Find() (terrible for performance).
1 Like
Thanks for the advice. But how would I communicate that info with the gameManager?
A method in the gameManager that returns an updated array of strings, and when you call it from your canvas you’ll be able to update the text accordingly. There are practically infinite solutions to a problem when programming, try thinking your own too;)
1 Like
Thanks!