NullReferenceException my worst enemy

Hi guys, this is my first time doing this. I don’t know If this is how you ask for help, advice, or guidance.
First, I’m having way too much fun doing the lectures and I’m enjoying the journey of learning scripting.

Ok, here’s the thing. This is for the BASEACTIONCLASS. When I am in GAMEMODE I can see a lot of NullReferenceException bombing my screen. But After I pick/chose my Unit it stop.

I can rotate the Unit as many times as I want. Then I move the Unit to a tyle/grid and he moves. But after that, I can’t do any more actions.

I don’t know if the NRE is doing this to the MoveAction scripts or something.

The NRE says is on the GridSystemVisual Script lines 50 and 78. But I compare the scripts and I don’t see any mistakes. (I did it more than 4 times, rewatching the videos too). I am 100% looking at the wrong spot, so I decided to ask for guidance. Just a little direction to where to look. Thank you in advance! :handshake:

NFE

SCRIPT

On the Console, you should enable Error Pause so the game pauses as soon as an error happens. It’s much easier to debug if you just look at the first error rather than hundreds, usually only the first one matters.
Then for debugging null, you look at the offending line and try to figure out what could possibly be null in there, I covered my debugging process in this video Code Monkey - How to Fix NullReferenceException in C#!
In that case on line 78, either the selectedUnit is set to null, or the GetMoveAction(); is returning to null
You can use Debug.Log to verify which is which. Check your UnitActionSystem, is the selectedUnit logic working?
Check the Unit script, did you correctly assign the moveAction field that is returned by that function?

1 Like

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

Privacy & Terms