NullReferenceException error

Everything worked until resetscore was written in LevelManager.

If i remove it with //comment then it works fine, but the score does not reset.

I cant find any errors in ScoreKeeper script either.

The error says its in line 18, levelmanager, but cant see any wrongs in that resetscore line…Help?!

I do have ScoreKeeper prefab on all Game scene and GameOver scene, which was shown in the next video. Still cant play from main menu or gameover menu, same error.

Hi,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

In your first screenshot, there is an error message in the Console. NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.

Also check if your “singleton” calls gameObject.SetActive(false); in the same if-block where Destroy(gameObject); gets called. If there isn’t that line of code, add it.

Hope this helps. :slight_smile:


See also:

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

Privacy & Terms