Context
Trying to recreate Super Mario NES world 1-1 in Unity. Having trouble updating the count down timer in the game UI (Legacy Text Object).
Setup
- Created a singleton UIManager with a
public Text coinCounterText;
field - Dragged a Text Object named CountdownText from the Hierarchy to the Inspector UI (1st image below)
- When the game runs, the public field becomes empty (2nd image below
Observation
- I can use
GameObject.Find("CountdownText").GetComponent<Text>();
to get hold of areference to the CountdownText object and update it accordingly - On game start up, I can see the reference of the CountdownText(Text) get renamed to
CountdownText(textSceneManager.LoadScene("1-1")
. - Log shows UIManager singleton was destoried at some point and got instantiated again during start up. (I assume it lost the references along the way)
Question
- What is the root cause of is issue?
- Is there a way that I can persist the reference to the Text object? (I do have
DontDestroyOnLoad(gameObject);
in UIManager’s Awake() but it is not working)