Whenever I click the start button or to return to the game, I get a “NullReferenceException: Object reference not set to an instance of an object.”
This is being thrown by the “scorekeeper.ResetScore()” method call in the “LoadGame()” method of the lecture.
I have a ScoreKeeper prefab in every scene. A scorekeeper is being found in my LevelManager’s Awake() method. But it’s somehow not being found when I call the “LoadGame()” method.
I am completely at a loss as to why it’s not finding my Scorekeeper object.
Here’s a snippet of my LevelManager code:
public class LevelManager : MonoBehaviour
{
[SerializeField] float sceneLoadDelay = 2f;
ScoreKeeper scoreKeeper;
void Awake()
{
scoreKeeper = FindObjectOfType<ScoreKeeper>();
Debug.Log("Scorekeeper found: " + (scoreKeeper != null));
}
public void LoadGame()
{
Debug.Log("gamestart - Scorekeeper found: " + (scoreKeeper != null));
scoreKeeper.ResetScore();
SceneManager.LoadScene("Game");
}