Length of path in grid cells

For an x-com style game where movement takes a limited amount of movement points, I’d like to calculate the graph length in grid cells, not Unity units.

How and where do I do that? I looked at OnPathComplete, but despite having set Pathfinding to never recalculate automatically, it’s called multiple times, so that’s not good. This is turn-based, so nothing else moves while the player moves and I could just use the initial path calculation. Movement can be around corners and obstacles, so I can’t just take the distance between start and end point, I need the actual path. I have the path calculation itself working, but can’t figure out how to get only the initial path length in grid units. Should be easy, right?

Hi

If you do not use any modifiers, calling path.vectorPath.Count will give you that. path.path.Count will also give you the same value (the second list is the actual nodes the path traverses).

OnPathComplete should never be called multiple times unless you manually call ai.SetPath/ai.SearchPath manually, though.

Oh brilliant. Actually, using path.path also lets me check if this is diagonal movement in case I want to have that cost 1.5 or something. Thanks.