I’m getting a NullRefrence exception when I try to do the last part of this tutorial.
As far as I can tell, there’s nothing different about this line and I’m doing what was done in the tutorial. Any help would be appreciated!
I’m getting a NullRefrence exception when I try to do the last part of this tutorial.
As far as I can tell, there’s nothing different about this line and I’m doing what was done in the tutorial. Any help would be appreciated!
I would first make sure you attached what you needed to attach in the inspector in the script category
Either textMeshPro
or gridObject
is null. Make sure you have something specified in the inspector for textMeshPro
and make sure that the gridObject
you are passing to SetGridObject
is not null. You can add some Debug.Log()
statements to check
private void Update()
{
Debug.Log($"textMeshPro is null: {textMeshPro == null}");
Debug.Log($"gridObject is null: {gridObject == null}");
textMeshPro.text = gridObject.ToString();
}
One of those will be ‘true’ and lead you in the right direction
So , it says that the gridObject is null, but I assigned it in the start function like it was shown in the video.
I tried to serializefield it and assign it manually but it didn’t show up in the inspector.
It’s being set in the GridSystem
class when we do the CreateDebugObjects()
Yeah, that’s correct. Make sure
GetGridObject()
method actually returns something other than nullGridDebugObject
somewhere in your hierarchyThe GetGridObject method is returning null, but since its only one line of code I’m not sure how to fix it.
Can you show the code?
So, this is returning an object from the array of objects. Did you set any objects in the array? It should happen in the constructor of GridSystem
So I forgot we could look at the scripts from this project, so I found out where I went wrong
I forgot the “for” loop in the GridSystem method. Sorry about that.
No problem. At least your problem is solved now
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.