So the odd mystery I was having yesterday was that the unit wasn’t updating it’s GridPosition when moving from point A to point B (well, it was sometimes). I solved the problem of returning to the starting GridPosition in the path by changing Unit.GetGridPosition() from
public GridPosition GetGridPosition()
{
return gridPosition)
}
to
public GridPosition GetGridPosition()
{
return LevelGrid.Instance.GetGridPosition(transform.position);
}
But, this is only masking a symptom, that being that the GridPosition is not being updated.
So then I turned to GridPosition itself, and I found that the Equals was
public bool Equals(GridPosition other)
{
return this == other;
}
Now my first thought was that in Update,
if(newGridPosition != gridPosition)
should be triggering a change every frame regardless, but for some reason this was not the case. It was generally not firing at all, In 2 movements, it didn’t trigger once!
Now the actual Equals(GridPosition other) should read
return x == other.x && z == other.z
When I made this change, grid position changes were properly registered each frame, and characters could move into abandoned positions. Additionally, characters didn’t return to the false starting gridPosition on subsequent moves, because they were properly registered on the GridPosition they were standing on.