Apologies if I’m asking a dumb question here, or it’s been asked before.
I’ve been going through all the GridSystem lectures again to try to get my head around how the grid stuff works, and I think I’m getting there. However I noticed the code being placed in the Unit script’s update function in this lecture:
GridPosition newGridPosition = LevelGrid.Instance.GetGridPosition(transform.position);
if (newGridPosition != gridPosition)
{
// Unit changed position
GridPosition oldGridPosition = gridPosition;
gridPosition = newGridPosition;
LevelGrid.Instance.UnitMovedGridPosition(this, oldGridPosition, newGridPosition);
}
}
Unless I’m misunderstanding something, this is checking every unit on the map, every single frame, to see whether or not it has moved GridPosition.
Would it be possible to only check this if the unit is moving (or better yet, some kind of UnitActive check in case I add a way for a unit to be moved by an enemy/ally ability even when it’s not its own turn), and would that provide a performance benefit? Or would I merely be replacing checking for movement every frame with checking for activity every frame, and not accomplishing anything?