Getting null reference exception when spawning my player instead of having it in the scene
This is related to the course for Galaxy Shooter on Udemy.
I am spawning my player through the "Spawn Manager" I initiate the uiManager
void Start()
{
_uiManager = GameObject.Find("Canvas").GetComponent<UIManager>();
- check for null-
}
Then when this function is triggered:
public void DamagePlayer()
{
_uiManager.UpdateLives(_lives);
}
I am getting: NullReferenceException
and if I do: _uiManager = GameObject.Find("Canvas").GetComponent<UIManager>();
Before I call _uiManager.UpdateLives(_lives);
then it works.
If I have the player being in the Game already and not being spawned by the Spawn Manager
, then there is no NullReferenceException
, why is that?
Your answer

Follow this Question
Related Questions
Null Reference for Spawning Character 0 Answers
Unity Networking Client NullReferenceException Error 0 Answers
Varialbes on prefab script always null 0 Answers
NullReferenceException: Object reference not set to an instance of an object error 0 Answers
CS1023 An embedded statement may not be a declaration or labeled statement help 1 Answer