Forum rules - please read before posting.

Pathfinding error

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:

Comments

  • Can you share the actual scene file? The Inspector alone isn't enough to recreate the issue.

  • edited September 2020

    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.

    originalNavMesh.TurnOff();
    newNavMesh.TurnOn();
    KickStarter.sceneSettings.navMesh = newNavMesh;
    newNavMesh.TurnOff();
    newNavMesh.TurnOn();
    
  • edited September 2020
    I'm afraid that even if I share the scene file, I have no reliable way of reproducing the issue.

    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.
  • edited September 2020

    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:

    • I only get the error when I have multiple navmeshes
    • Removing the RememberNavMesh2D component on "Other nav mesh" makes it go away so it's related to saving/loading
    • It never happens on the first load, you have to re-enter the scene x amount of times (x seems to be different for different scenes so it might be a race condition depending on hardware so if you don't see the error after hitting the box hotspot - try again or add more scene reloads)
  • I think I'm missing a file or two. There's no scene file here.

  • Open up RememberNavMesh2D and replace:

    KickStarter.navigationManager.navigationEngine.ResetHoles (navMesh);
    

    with:

    if (KickStarter.sceneSettings.navMesh == navMesh)
        KickStarter.navigationManager.navigationEngine.ResetHoles (navMesh);
    
  • Boom! Gonna need a beer to celebrate that one 👊

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.