3d Platformer Tutorial GUI problems

I’m trying the 3D Platformer Tutorial and am getting this error:

NullReferenceException: Object reference not set to an instance of an object
GameHUD.OnGUI () (at Assets/Scripts/GUI/GameHUD.js:40)

How would one go about fixing this? Nothing displays when you run the game.
Any help is appreciated.

DemetriusB

Did you check what was on GameHUD.js line 40 that was looking for the null object, and make sure it’s being instantiated correctly? Null Refs are usually caused by something simple.

Here’s the code from line 40. This isn’t my code, but the code from the tutorial.

var itemsLeft = playerInfo.GetRemainingItems(); // fetch items remaining – the fuel cans. This can be a negative number!

Any help is appreciated.

Demetrius

Probably playerInfo is not instantiated or GetRemainingItems() is trying to access a null object. I haven’t done the tutorial, so I don’t know its inner workings.

If you’re not comfortable finding Null Refs, maybe you should try an easier tutorial than the 3D platformer to get comfortable first.

I did the 2D tutorial, no problem. The First person tutorial, had way too many issues with the code. Struggling to get this working at this point. Even the 3D Platformer, had many issues, but I was able to solve many of them.

If any body has done these tutorials and solved this issue, your help is appreciated.

Demetrius

I figured out my problem with the help of Tom at the Unity3D support staff. Thanks to everyone for their help.

Demetrius

As I recall when the 3D platformer tutorial was under development, Sean said that the intention was for the user to go through the entire tutorial and complete a fair number of scripting and IDE configuration tasks to make it work. It doesn’t just work to build it out of the box.

That means that the code isn’t necessarily just plug and play without working through the tutorial to a significant extent.

Can you tell us how to make it work? Cause i have the same problem too

@Mitendrius: can you post the code that is causing this error and the line number quoted in the error message? This is a very general kind of error and the solution depends on the code you are using.

Add the Third Person Status script to the LertzPrefab in the inspector. This script has the implementation of GetRemainingItems()

This solved the problem for me. Perhaps the tutorial should be updated to add this set of steps.

Thanks @tpelham