TurnBased Unit static event, TurnSystem issues

Everything works so far. I don’t know if they’re related but I’m getting a null object reference from my GetGridPos lamda in my LevelGrid class. Also I can’t seem to reset the action points. As I troubleshoot I find I can’t to use debug log or the Unit’s start function. It’s odd because everything works. Just can’t reset the action points and the null object from my get grid. Any insight?

I am able to click my button and increment the next turn. The unit is spending the correct points. I AM able to see the unit’s gridPosition, but can’t seem to find the null reference.

NullReferenceException: Object reference not set to an instance of an object
GridLevelSystem.GetGridPosition (UnityEngine.Vector3 worldPosition) (at Assets/BruuScripts/GameManagers/GridAndUnitScripts/GridLevelSystem.cs:59)
Unit.Start () (at Assets/BruuScripts/GameManagers/ActionScripts/Unit.cs:21)

Check line 59 of the GridLevelSystem.cs. Can’t help much more than that without the code

This is line 59
public GridPositionSystem GetGridPosition(Vector3 worldPosition) => gridSystem.GetGridPosition(worldPosition);

This is the lamba it’s pointing to.
public GridPositionSystem GetGridPosition(Vector3 worldPosition)

{

    return new GridPositionSystem(

Mathf.RoundToInt(worldPosition.x / cellSize),

Mathf.RoundToInt(worldPosition.z / cellSize)

    );

}

Check gridSystem. That’s the only thing that could be null there

As the null reference is originating in Unit.Start(), it’s possible that there is a race condition going on…

Paste in your complete Unit.cs and GridLevelSystem.cs scripts and we’ll see if we can get this sorted.

1 Like

Yeah, That’s the logical option, and I did trace back to see where it would’ve been called(The Unit). Thanks for your insight.

Funny story. That’s exactly what I did yesterday and the null exception is gone. I’m really grateful for everyone’s diligence.

Privacy & Terms