Can't fix null reference exception

I’ve tried to do what others here did to fix their null reference exception but nothing is helping. My code is the same, to the point that I even tried copy-pasting the code from the resources and it still happens. I’ve made sure the griddebugobject prefab has the text reference dragged. There is no griddebugobject still in my hierarchy. Adding debug.logs to my update function in GridDebugObject.cs returns true for gridObject being null and false for textMeshPro being null. I am so confused and any help would be very appreciated because I’ve had a lot of frustration today with trying to learn this stuff.


image_2023-08-26_223012514

It’s not.

Your problem is in the CreateDebugObjects method. You overwrite all the objects in the grid here


All the objects you placed in the grid is being removed with this line, so when you call GetGridObject it returns null for all the objects. Remove that line, it shouldn’t be there

Huh. Well that worked but I’m even more confused now. If that line isn’t supposed to be there then I don’t know why I had it there. And I don’t know why I kept getting the error when I replaced my code with CodeMonkey’s. I guess I must be remembering wrong…
Either way thank you for all the time you spend helping people like me.

Looking at your code screenshots, I suspect you copied and pasted the loops from the constructor and accidentally included the line

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

Privacy & Terms