Hey there,
I’m getting a null exception when trying to get the grid position of the unit in the SpinAction class.
Here’s the error:
NullReferenceException: Object reference not set to an instance of an object
SpinAction.GetValidActionGridPositionList () (at Assets/Scripts/Actions/SpinAction.cs:50)
GridSystemVisual.UpdateGridVisual () (at Assets/Scripts/Grid/GridSystemVisual.cs:56)
GridSystemVisual.Update () (at Assets/Scripts/Grid/GridSystemVisual.cs:46)
Basically, I think the unitGridPosition is not getting anything from unit.GetGridPosition in SpinAction.
Here’s the code I have:
public override List<GridPosition> GetValidActionGridPositionList()
{
GridPosition unitGridPostion = unit.GetGridPosition();
Debug.Log(unitGridPostion);
return new List<GridPosition> { unitGridPostion };
}
I added the Debug.Log for testing, but that’s pretty much the code block from the lecture. The same line in MoveAction does return the unit’s GridPosition, but let me at least show the relevant BaseAction lines too.
BaseAction implementation:
public virtual bool IsValidActionGridPosition(GridPosition gridPosition)
{
List<GridPosition> validGridPositionList = GetValidActionGridPositionList();
return validGridPositionList.Contains(gridPosition);
}
public abstract List<GridPosition> GetValidActionGridPositionList();
I’ve double-checked the reference scripts on the GitHub and tried to comb through my scripts to see if I can track it down, but I have had no luck. I feel like it’s got to be obvious, but I’m just overlooking it.