I have a scene in which often get the following warning (followed by the character walking straight through an obstacle):
"Pathfinding error - cannot build spanning tree from..."
It happens a lot but I have not been able to reproduce this in a reliable way. I have been experimenting a lot though and I noticed that running an ActionNavMesh action and setting the same navmesh that is already active on the scene it starts to work again (only then it's too late since the player already walked straight through an obsacle). Looking closer into it I found your comment about needing to turn off and on the navmeshes in order to get weight caching to work. I added this fix that applies the mentioned strategy if needed and then runs the method again instead of showing the warning - so I replaced the null checking of the preced var with this:
if (precede == null)
{
Debug.Log("Pathfinding fix applied applied");
KickStarter.sceneSettings.navMesh.TurnOff();
KickStarter.sceneSettings.navMesh.TurnOn();
return GetPointsArray(_originPos, _targetPos, _char);
}
It's probably best passing an integer or bool into GetPointsArray to let it know if this is a retry (not to get stuck in a recursive loop).
While this works, it's a pretty brutal solution and it's probably best if you could find the root cause for this.
Here's a couple of facts about the scene that might help to recreate this:
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Can you share the actual scene file? The Inspector alone isn't enough to recreate the issue.
I think that you're outside of the NavMesh.
I had similiar issue. Two NavMeshes, the problem was how I was switching the NavMeshes. I was doing it in script, not with Actions. They were not switched properly. Are you by any chance doing it with script too?
I looked inside AC's code how the action handles the switch. Did something similiar and it started working.
Thanks for chiming in @Keks, I'm using script but my script is executing an action (using CreateNew()) to switch between the navmeshes. So the code in the actual action is being executed.
On entering the scene I'm teleporting the player outside the navmeshe into an elevator that is then lowered into the navmesh. But the issue can happen (on the same scene) without the player riding the elevator.
If the root cause (mentioned in Chris's comment in the action in question) cannot be addressed, the fix I'm suggesting might be a good idea. Any theories are much appreciated though.
Your Inspector shows one of your NavMeshes has a hole in it - what is this shape, and what of the other NavMesh?
Is this also occuring if you remove the other NavMesh and/or the hole from the active?
Please share whatever you can about this issue - there really isn't enough for me to go on as it is.
This was probably the hardest AC issue I ever managed to reproduce, but here it is:
https://1drv.ms/u/s!Amz_vh8OYDX3vL8d2A1MFTV-mkfPGw?e=312Src
Instructions:
Play Scene 1, click the box hotspot. If this doesn't give you the error, see my last note.
Note:
Many thanks.
I think I'm missing a file or two. There's no scene file here.
Try this one:
https://1drv.ms/u/s!Amz_vh8OYDX3vL8g7wDvAPCOE8TUug?e=TqxcCG
Open up RememberNavMesh2D and replace:
with:
Boom! Gonna need a beer to celebrate that one 👊