Moving from Unity NavMesh to A*Pathfinding - How to do certain things?

Hi everyone,
I’m moving from Unity NavMesh into APathfinding and I’m trying to understand a couple of things and how to convert my code to use APathfinding instead.

For my case, I’m using Recast graph in a 3D game and RichAI agent

There are 2 particular things I’m looking for

1. Check if “agent” can move and reach the target without actually starting to move it.

What I’m doing today (with Unity Navmesh) is to get the destination point, calculate the agent path for that point and then only execute the move if there is a path to the target point.

Would anyone be able to point me in the right direction regarding this? Not really sure if I should be interacting with the Seeker or the AI class for this (probably both?) and what methods I should be using.

2. How to update the navMesh without freezing the scene and/or update just certain areas of the mesh
My scene has a couple of isolated areas which are covered by the mesh (making multiple isolated mesh areas). right now (using Uniti NavMesh) when I update the mesh, there is a 1sec freeze on the scene when the mesh updates and I want to get rid of it. would this be a problem with this asset? is there a way to make the update asynchronous so that the freeze doesn’t happen?

Is it also possible to just update a specific area of the mesh reducing the amount of calculations needed? (I’m assuming this may be possible if the mesh is using tiles but not sure how that is done)

Would anyone be able to point me in the right direction regarding this?

Hi

  1. You can use PathUtilities - A* Pathfinding Project
  2. In 5.0, recast graph updates are async by default. You can update the graph using AstarPath.active.UpdateGraphs(bounding box). See Graph Updates - A* Pathfinding Project
    And yes, with a tiled recast graph it will only update the tiles that the bounding box touches.

The “nodes” are triangle bits that together form the mesh correct?
And is it also advisable to use the PathUtilities.IsPathPossible() in a coroutine or it’s fine to call it directly?

I’m trying to use it but it’s complaining that it can’t convert from Pathfinding.Graph to Graph?
I’m using the example from the documentation.

 if (Physics.Raycast(ray.origin, ray.direction, out var hitInfo, Mathf.Infinity, layerMask  )) {
         
    GraphNode startNode = AstarPath.active.GetNearest(this.transform.position, NNConstraint.Walkable).node;
    GraphNode endNode = AstarPath.active.GetNearest(hitInfo.point, NNConstraint.Walkable).node;

    if (PathUtilities.IsPathPossible(startNode, endNode)) {
        // Yay, there is a path between those two nodes
    }

On the UpdateGraphs(), the bounding box is the area I want to update correct?

I’m not sure I understand the NNConstraint. In my case, my graph is already only considering certain layers that contain the “tiles” that can be walked on. Would I need to still add the NNConstraint.WAlkable in this case?

In which case would I want to use these constrains?

Yes

If you don’t specify any tags in the IsPathPossible call (there’s an optional parameter with a tag mask), it’s really really cheap. So you can call it whenever.

Yes

For a recast graph, usually all nodes are walkable anyway, so the difference between NNConstraint.None and NNConstraint.Walkable doesn’t really matter. There are, however, cases where you mark individual nodes as being unwalkable, or you might only want to find nodes with specific tags, etc.

Pathfinding.Graph is not a type that exists, so I don’t think that’s quite correct.

this is what I see

And in case it’s relevant, I’m using

using System.Collections;
using UnityEngine;
using Pathfinding;

:grimacing:

Looks like you might have another class named GraphNode in your project?

or can I simply set the RichAI.destination directly?

Definitely. Just set ai.destination = point.

Looks like you might have another class named GraphNode in your project?

Now that you mention it… I think I do indeed… will check it out.

Definitely. Just set ai.destination = point .
and if I want to "force " to start to move/calculate now and stop the previous movement, I should also call the StartPath(), correct?

Yes. Normally it will recalculate its path very quickly if it detects that the destination has changed significantly (within a few frames), but you can call ai.SearchPath() to make it recalculate its path immediately.

Btw. The new FollowerEntity component is for most situations better than the RichAI component.
Excerpt from blog post:

Will give it a try.
Was using the RickAI because it was your initial recommendation (on a post a way back)

I will get there (the error is also fixed).
Thank you for your patience :sweat_smile: