Can't make ITraversalProvider to work


I have made a simple scene using tags, using RecastMeshObj and RecastGraph

Then I created a traversal provider to prevent agent going from tag2 to tag3 directly (I want to force agent to go through tag1 area, so any connection not starting or not ending with tag1 is denied):

    private class CustomTraversalProvider : ITraversalProvider
        public bool CanTraverse(Path path, GraphNode from, GraphNode to)
            if (from.Tag != to.Tag && from.Tag != 1 && to.Tag != 1)
                return false;

            return DefaultITraversalProvider.CanTraverse(path, to);

I setup a FollowerEntity spawning in tag2 area, with a AIDestinationSetter whose target is in tag 3 area.
At runtime, using a debugger, I can see my custom ITraversalProvider is being called, and the false branch is being taken. However, the agent goes straight from area tag 2 to area tag 3 without doing a detour in tag1 area.
Is there something I forgot to make this all work?

Also, I tried quickly with a RichAI and it worked:

Thanks in advance!

Thanks. The FollowerEntity did indeed not take connection filtering into account. I’ll make some fixes in the next update. The path was generated correctly, but the FollowerEntity immediately simplified the path.

1 Like

Thanks, looking forward to try it!

I have two quick follow-up questions:

  1. Can RVO push my character outside of what CanTraverse allows? If yes, will it try to go back on the “allowed” node first? I am afraid if it gets pushed away and triggers a path recalculation from wrong area, it will end up taking the “forbidden” path.

  2. Would it be possible to expose “future planned path”? I would like to do queries about what lies X meters ahead (or if not possible, X nodes ahead). Ideally in forms of ranges so that I don’t have to do tons of query to be sure to not miss anything.
    For example, having public access to pathTracer.nodes (from what I understood, it would only give list of next nodes without accurate distance since it’s before funneling – but it would still be better than nothing).

Also, just an update on the original issue:
I ended up creating a GraphModifier to remove the connections between those areas, it makes much more sense for my use case since it is not going to change at runtime.

A little bit about my use case, main area (tag 1) is sidewalk and tag 2/3 are separate crosswalks.
I wanted to make sure pedestrian go back to sidewalk before taking next crosswalk, even if they are slightly connected (which could easily happen in a corner).

So no hurry to fix the original issue, the current workaround seems to be working fine.

Does IAstarAI - A* Pathfinding Project work for you?

The FollowerEntity will usually prevent this. Not quite sure if there might be race conditions where an agent is pushed over a forbidden connection, and the path is recalculated during the same frame.

Yes, that’s what I am currently using.

However, I was thinking it would have been nice to be able to easily query the GraphNode future list being traversed (without having to resolve Vector3D → GraphNode again), so that I could figure out all “tags” being traversed or what tag is at a specific distance marker easily.

More specifically, I want my character to stop a bit before entering the “crosswalk” area. Right now I make it stop only when FollowerEntity.currentNode.tag is crosswalk (so it is right on the edge) but ideally I would like to be able to stop 50cm before.
I guess I could compute 50cm ahead using GetRemainingPath() and then do a, but if this GraphNode was already stored in the Path without having to do a lookup, I thought that would be more direct/fast.

Anyway, I can work it out with current system so no worries.

Thanks, good to know!