Ensuring path still valid

Situation: I have an RTS with a grid graph. To check whether path still ok (area hasn’t been walled off), I am using node.Area. I cache the gridNodeBase for the destination then check its area vs. the open area (uint 1) every frame. This seems to work well, distinguishing walled off vs. not areas perfectly well… except when the graph updates. That is, placing or deleting a single wall, even if it should not change any area results in the .Area == 1 check to fail for a single frame. It doesn’t seem to fail every time for every agent, so it’s a bit strange. My overall goal is to cancel the agent’s behavior if and only if its path is now really invalid, so these semi-random failures aren’t reliable enough.

Idea to Fix: What I could do is count the number of frames it has failed in a row, and if too high then consider the path to be truly invalid.

Question: Is this the right approach? Is there a better solution? Why does it fail for just a frame?

Hi

Which version of the package are you using? I don’t think this should happen in version 4.2 and above.

Also. You might want to use IsPathPossible instead of .Area==1 as the largest area being area 1 is just a coincidence, not guaranteed.

Aha - so I’m on 4.1.6. I’ll upgrade then ping this thread again if the problem persists.

1 Like

Works great! One question: what’s the best way to infer “largest / main area” if 1 is not reliable? Traverse whole graph and count? I’d like to issue “A unit is stuck!” warning to player.

Hi

There’s not much else you can do than to iterate through the graph and count it.
However if you have a known point which is guaranteed to be part of the area you are interested in (maybe the player’s position?), you can just find the closest node to that point.