Null Reference Exception Error

Hello, I am having the same issue as described here:
Tower Instantiation Broke12nod7g_gaMzgyMzU3ODk2LjE2MjE5MjU3MTc._ga_2C81L26GR9*MTY0MTg0MTQ1OS4zNTkuMS4xNjQxODQzNTI5LjA.

However, after watching the video on Script Execution, it did not solve my error, it did solve the error in question in that video, but not this.

I am getting the error when my Object pool initializes, and When I try to instantiate a Tower.
I get a null exception error in the Console, but when I look in the inspector everything is assigned as it had been before implementing the new code changes…

the error I am getting is

NullReferenceException: Object reference not set to an instance of an object
PathFinder.BuildPath () (at Assets/Game/PathFinder.cs:120)
PathFinder.GetNewPath () (at Assets/Game/PathFinder.cs:81)
PathFinder.WillBlockPath (UnityEngine.Vector2Int coordinates) (at Assets/Game/PathFinder.cs:134)
Tile.OnMouseDown () (at Assets/Game/Grid/CoordinateSystem/Tile.cs:73)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

This error shows 6 times upon initialization (once for each of the objects in the pool) and each time I try to add a tower.

Hi,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message. To which line in your code does it refer?

Thanks Nina, I just went through my code and compared it to the Project Files in the lecture files, and found my mistake… in the BuildPath() method I had while(currentNode != null), instead of while(currentNode.connectedTo != null)… that seems to have fixed the issue I was experiencing. Thanks!

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

Privacy & Terms