Error: This part should never be reached

Aight I’ll try to give as much detail as possible code wise.

  1. Initial scan of the graph at the start of a session (this code happens inside a coroutine)
    // Pathfinding needs to be scanned once, otherwise it won't work on start
    foreach (var _ in AstarPath.active.ScanAsync()) { yield return null; }
  1. Spawning the player in the already scanned environment (the target corresponds to where the player is being spawned on, i.e. same position)
    // Need to search the path once, otherwise pathfinding does not work the first time around
    aiDestinationSetter.target = target.transform;
    movement.SearchPath();
  1. Requesting to move the player by checking if there is a valid path and if so setting the destination
    private IEnumerator RequestMove(Transform target)
    {        
        var path = Seeker.GetCurrentPath(); // Removing this and just using Seeker.StartPath() does not make a difference.
        path = Seeker.StartPath(player.transform.position, target.position);
        yield return StartCoroutine(path.WaitForPath());
        
        if (path.error)
        {
            // Player does not move
        }
        else
        {
            aiLerp.CanMove(true);
            aiDestinationSetter.SetDestination(target);

            // Player does move
        }
    }
  1. This is a special case but I scan the graph again when a chunks are finished loading. This is usually called every 15 to 30 seconds depending on how fast the player moves. I simply wrapped this in a try catch as it was throwing an exception when I was already scanning the graph asynchronously (which happens once at the start of the game, after that the try catch is technically not needed).
    private void OnChunksProcessed()
    {
        try
        {
            AstarPath.active.data.gridGraph.Scan();
        }
        catch 
        { 
            //
        }
    }

InvalidOperationException: Another async scan is already running
AstarPath+d__123.MoveNext () (at ./Library/PackageCache/com.arongranberg.astar@4.3.82/Core/AstarPath.cs:1621)
AstarPath.Scan (Pathfinding.NavGraph graphsToScan) (at ./Library/PackageCache/com.arongranberg.astar@4.3.82/Core/AstarPath.cs:1543)
AstarPath.Scan (Pathfinding.NavGraph graphToScan) (at ./Library/PackageCache/com.arongranberg.astar@4.3.82/Core/AstarPath.cs:1511)
Pathfinding.NavGraph.Scan () (at ./Library/PackageCache/com.arongranberg.astar@4.3.82/Graphs/NavGraph.cs:338)

  1. Lastly I perform local graph updates if an object is removed from the world, but I simply do this by defining the bounds and executing the following code.
    AstarPath.active.UpdateGraphs (bounds); 

These should be all occurrences where I directly interact with the pathfinding system.

€: Also here is a better stack trace of the error I’m getting in the version 4.3.64, maybe with that you can determine if the issue was actually fixed in subsequent versions. The ‘JobCopyRectangle’ exception points to the way I scan the graph, i.e. ‘AstarPath.active.data.gridGraph.Scan()’ and the ‘This path has not been started yet’ exception points to the ‘WaitForPath()’ method.

Error.txt (33.3 KB)

@aron_granberg

Here a screenshot of the path object that is being created from my requests. I’ve noticed that the start node is not set to anything, could this pose a problem?

€: I just checked in the previous version where my pathfinding still works and the startNode was set.

€²: I just tried to set the startNode manually, but unfortunately it does not have a setter anymore.

I’d recommend to instead check AstarPath.active.isScanning before you try to scan the graph.

In 3. You are calculating a path using the Seeker. This will get picked up by the agent and it will start to follow it. If you just want to check if there is a valid path, I would instead recommend using PathUtilities.IsPathPossible: PathUtilities - A* Pathfinding Project
This avoids you having to use a coroutine to wait for the path calculation as well.

This is not an issue. The implementation was changed a bit, but this is nothing to worry about.

I’m pretty sure it is fixed in later versions.

1 Like

Hi

Ah. Found the issue in the project you sent me.
You had ASTAR_GRID_NO_CUSTOM_CONNECTIONS enabled in the Optimizations tab. There was unfortunately a bug causing pathfinding not to work on grid graphs if that was enabled. It was already fixed in my dev version, but I had not released a new beta with it yet. It will be included in the next beta update (will probably be released today or tomorrow).

2 Likes