I have a scene that I can load from a main menu.
The scene involves units spawned from 2 sides facing each other and using a very simple NavMesh on a square-shaped area with everything set as “Walkable”.
The units spawn and are then given a NavMeshPath if the NavMesh.SamplePosition() function returns a hit. However, when I launch the scene:
- first time always works
- second time no hits
- third time always works
- fourth time no hits
And so on and so forth. I’m obviously missing something here but I don’t know what. Anyone has any idea?
What parameter setup are you using to call NavMesh.SamplePosition()?
Maybe your max distance is too small. Do you use areaMask or NavMeshQueryFilter?
Posting some code would help.
Looking at the screenshot, you seem to use a NavMeshObstacle for moving units. This works for a few units but if you scale up to more units it will get a problem.
Carving will trigger a Repath for all units positioned on the same navmesh. At some point, the units will get stuck as carving calls happen every other frame.
1 Like
First thank you very much for getting back to me on this!
My NavMesh setup can’t be the problem because when I launch the scene only once it works perfectly. It also works perfectly the 3rd time around. It’s only on the even times I relaunch it that it doesn’t work.
So I think it’s something that persists between the times I launch the scene from the Main Menu somehow but I wasn’t able to find which element is not reset properly yet.