Agents falling off of complex navmesh

Hi @aron_granberg

Wondering about an issue i’m having with agents falling off of the navmesh, as shown in the video above. You’ll see the red agents moving around the mobius strip, shooting, and eventually they just fly off the nav mesh. Later in the video you see one fly off and reattach itself to a part of the navmesh, but it just gets stuck there.

This is all setup like Example19_Spherical in the beta, so it’s Navmesh, RVO, etc. I’ve tried Constrain to graph but that doesn’t work, they still fly around at some point pretty quickly. I’ve also tried the Clamp to Navmesh script included in the A* package, but then agents just get stuck in a location, not able to move at all it seems.

Any advice on how to restrict them to the structure? Maybe make their movements a little less jerky as well :slight_smile: If you need any more info just let me know. Thanks!

Wow, that is indeed a really complex navmesh.

I’d try something like:

void Update () {
    ai.position =;

to see if that works.
Disable constrain to graph (it doesn’t work well for non-planar graphs).

Also, if you can, make your collision mesh pretty smooth. That will allow the agents to move across it better.

Thanks! This seems to help but is also a big performance hit with even a couple units. Seems like I can get away with calling it less frequently than the Update loop, but need to test it out more.

Just to be clear, you’re updating the transforms position and not a value in one of the A* scripts, right? Are there any redundant interactions happening with doing this while using Seeker / RVO Controller / AI Path aligned to Surface / Funnel Modifier on the AI units?

Thanks so much!

Some updates on trying to address this performance drop @aron_granberg

I made an inherited AI Path Aligned To Surface class that added your Get Nearest suggestion on update and it seems to work, but massively decreases performance. I have a drop from 60+ FPS to roughly 20 FPS. This is in editor, with 5 enemy units on the mesh. At some points it even drops to 5 or 6 FPS. Profiler shows it’s definitely the addition of Get Nearest.

I’ve also tried calling it less frequently, hoping to strike a balance of staying on mesh and using less calls, but after a short amount of time the enemies will fly off the mesh.

Any ideas of how to better implement this? Have I headed down the wrong direction with how to use this?

Appreciate all your help!

EDIT: Also want to note, after this I tried upgrading to the latest beta just to try things out, and now all of my enemies throw this error from my custom script, which only adds the suggested GetNearest to the update of AIPathAlignedToSurface

transform.position assign attempt for ‘Enemy Dodeca AI 2(Clone)002’ is not valid. Input position is { Infinity, Infinity, Infinity }.
UnityEngine.Transform:set_position (UnityEngine.Vector3)
Pathfinding.CustomAIPathAlignedToSurface:Update () (at Assets/Scripts/CustomAIPathAlignedToSurface.cs:15)

Another update! Fixed the whole infinity thing, seems it was an issue with the saved graph cache and having updated to the newer beta.

Have this working now, and it seems like on beta 71 i’m not getting the massive performance decreases I got before, but still seems to effect frame rate substantially. Still wondering how to best improve performance, if you have any advice it would be appreciated, thanks!

1 Like

I’m not quite sure what the best approach would be. Perhaps a faster option could be to rely on the physics engine and do a sphere cast to try to find a close-enough position to snap to?