We use a script that says “take this objects transform, then randomly choose a position at 360 degrees and 100 units out, and spawn an enemy somewhere on the perimeter of that circle.”
If I turn off the NavMesh and just run it, the script itself performs great. It will drop enemies randomly around that perimeter.
However, when I turn NavMesh on, they still spawn where they are supposed to, but some of them will “shoot” off to some other point of the map. Its almost like the NavMesh forces them off to some other “more suitable” point of the map. If I bake a mesh with 0 objects in the scene, and it is a perfectly solid blue plane, then they act fine. If I have a lot of objects in the scene and bake, then you get all the intricate geometry of the NavMesh. Which, seems to be the issue. The more complex, the more “dead” areas I have. Where now all the enemies actually span in the circle, but are immediately and very quickly shot over to some other point of the mesh that usually isn’t inundated with these lines in the mesh.
To clarify, I know how to setup NavMesh parameters, and have tried an immense amount of variations. My actual ground in 100% flat through the whole thing. The only things I have really are height, to say what enemies can fit under, and radius, being how far around objects to avoid.
It turned out (for some odd reason) we had to turn off the NavMeshAgent in script, then turn it back on just after the character spawned. I also think this has something to do with the fact that the enemies are pooled, and just respawned over and over and never actually start the game instantiated and on the ground.
So, if you come across this issue, I would say to turn off the NavMeshAgent component by default, then when you spawn or respawn, activate it, when the character dies and is “destroyed” (more like deactivated) THEN turn it off, and keep it off till you instantiate him again in his new location. MAybe wait a half second after he spawns, then activate. This solved it for us.
Same problem; this solution worked for me. Would still like to know what the actual reason this works is though, i.e. if its a specific number of frames, wall time, moon phase, UT HQ coffee pot state, etc.
Still running into this issue in 2019 lol.
The disabling/enabling NavMeshAgent component thing did work for me. For my specific issue though, I didn’t realize at first but I had a SetDestination function with coordinates that are supposed to be updated every few seconds in the update loop (I’m making this game for VRChat, so I thought I need it for syncing on their platform, if I wanted the enemies to appear to be doing the same thing on every players screen). Anyway, the Vector3 that goes in the SetDestination function, when initially enabled, has no value, so I guess it defaults to (0, 0, 0). Once I realized that and just removed that line altogether the agents started behaving correctly. I’m still leaving in the enable/disable logic for the NavMeshAgent component though, feels cleaner than it did before. Thanks for asking this/updating with your solution!
Simply use gameObjectName.NavmeshName.Warp ( position );