Why Singleton don't work well?

Why Singleton don’t work well?
In the lesson, the first time the score update well.
Then die, and play again. The score didn’t update.
I find out it’s because the ScoreDisplay.cs get the “wrong” GameSession.

I use Debug.Log("gameSessionCount = "+ FindObjectsOfType().Length); in the ScoreDisplay.cs Start().
And, there are 2 GameSession after playing over two times.

Hi Mado,

First of all, good job on analysing the problem. There are indeed two GameSession objects in the scene because the Destroy method does not destroy game objects immediately. It destroys the game object at the end of the frame.

In one of the next lectures, Rick adds another line to the same code block as the Destroy method: gameObject.SetActive(false);.

That fixes the issue for him. For you, too?

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms