Don't Understand the Logic

We are getting reference of gridManager in the Awake but the in the SetLabelColor() Method we are saying if gridManager is null then we will return Early and then we are getting GetNode() method. it causes us a null reference exception untill we say if node is null we want to return early.

But main question is if we find gridmanager in awake then it should not be Null in the SetLabelColor();
Am i missing something? I hope this question dosen’t sounds dumb i am new to unity.

139

Hi,

Just because a GridManager object is assigned to the gridManager variables does not mean that the GetNode method returns a Node object. The two objects are not the same. If you get a NullReferenceException with node.isWalkable, you have to check the code of GetNode. Maybe it is wrong, or maybe the coordinates do not exist in the dictionary.

To figure out what’s going on at runtime, use Debug.Logs. Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

I hope this helped. :slight_smile:


See also:

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

Privacy & Terms