Getting NullReferenceException Error

Hi as per the user before, I am getting the same error.
Following your advice to him, I confirmed that the gridObject was indeed null.
So I then put a the debug.log before my 'gridDebugObject.SetGridObject(GetGridObject(gridPosition));

ConsoleLog_Output

In the console you can see the 2 dimensional array being completed successfully. And then the nullExceptionError.

I have looked and looked and am sure there are not spelling mistakes or syntax errors, but I have been looking for a long time…

Any advice much appreciated


You have pasted code from CreateDebugObjects but the error happens in the Update of GridDebugObjects (on line 20)

Thought I included the two files, thanks for letting me know

Ok, I think I know what’s happening

In the CreateDebugObjects method, you create an instance of the debugPrefab, but then you do nothing with the instance, so when Update fires on it, the m_gridObject is null.

You will see on the next line that you are getting the GridDebugObject from the prefab and not the instantiated object. You should change to debugTransform.GetComponent<GridDebugObject>();

1 Like

Thank you, That worked :smiley:

But am really really confused still as I do not understand why the course says do it that way as below

I do intend to go over the videos from the start of this section again, as I obviously need to understand it better :slight_smile:

Thanks again for all your help

It doesn’t

image

It does exactly what I suggested you change

1 Like

Yup always be very careful so you only use the prefab for instantiating and don’t keep modifying it after that.

2 Likes

Sorry Man, I must of been more tired than I thought to totally mis see that !!!
Thanks again for setting me on the straight and narrow :smiley:

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

Privacy & Terms