Checking if an object would block a navmesh path before actually placing it

Is there a good way to check if some object would completely block a navmesh path from one location to another without actually placing the object?

You mean you’d like to know whether spawning-in a given actor would block a stored path or not? If so I can only suggest using FNavigationPath::DoesIntersectBox as a reasonably good approximation. This function is not exposed to BP, but exposing it would really easy so just let me know if you need that.

Cheers,

–mieszko

Thanks for the suggestion Mieszko! However, I would like to know if there was any path from point A to point B if an actor would be spawned somewhere. The player should be able to build almost everywhere but I want to make sure that he can’t completely block the way to some specific target.

You’d need a way to be able to say “this area is untraversable for this pathfinding request” when checking if a path would be blocked before the actor was spawned.

You could do that by implementing a custom navigation query filter, derived from FRecastQueryFilter, and overriding passVirtualFilter to detect the forbidden polygons and discard them.

Now this method is not ideal, since as soon as you spawn a new “path-blocking” actor the topology of navmesh will change, and local subdivision of navmesh could end up being totally unrelated to whatever you’ve tested before actor’s placement.

Just a tip from my experience, in such cases you always need to design a fallback behavior, like AI being able to destroy obstacles. In dynamic worlds you simply can’t foresee everything, especially if the players are free to build stuff.

Cheers,

–mieszko

Thanks for the help Mieszko!

I guess I could just destroy a path-blocking actor immediately after spawning it. However, testing the navigation path right after spawning the actor does not seem to work and I’m guessing the navmesh is not built synchronously right after each spawn. Using C++, how will I know when the navmesh is updated after spawning an actor and I can test the path against it?

NavigationSystem.IsNavigationBeingBuilt is a BP-callable function that you can use. On C++ side there’s even more options, look through NavigationSystem’s API.

In near future I’ll add a delegate that will broadcast information when navmesh is done building, so it will be a lot easier to base logic on it.

Cheers,

–mieszko