[ BUG ] FollowerEntity ignores traversable graphs until the first path calculation

I have several Recast graphs and each agent moves only along one of these graphs, for this I set up traversable graphs.

I encountered large performance spikes on the Repair/GetNearest marker when spawning a large number of agents. These spikes are not observed when the graph is single.

What I found about this:
When the agent is assigned the first destination and before the first computed path is received, the agent searches for the closest position with GraphMask.Everything.
This happens here:

at AstarPath.GetNearest (UnityEngine.Vector3 position, Pathfinding.NNConstraint constraint) [0x000f6] in .\Library\PackageCache\com.arongranberg.astar@5.1.6\Core\AstarPath.cs:2280
at Pathfinding.PathTracer.RepairFull (UnityEngine.Vector3 point, System.Boolean isStart, Pathfinding.PathTracer+RepairQuality quality, Pathfinding.Util.NativeMovementPlane movementPlane, Pathfinding.ITraversalProvider traversalProvider, Pathfinding.Path path) [0x002f5] in .\Library\PackageCache\com.arongranberg.astar@5.1.6\Utilities\PathTracer.cs:866
at Pathfinding.PathTracer.Repair (UnityEngine.Vector3 point, System.Boolean isStart, Pathfinding.PathTracer+RepairQuality quality, Pathfinding.Util.NativeMovementPlane movementPlane, Pathfinding.ITraversalProvider traversalProvider, Pathfinding.Path path, System.Boolean allowCache) [0x00262] in .\Library\PackageCache\com.arongranberg.astar@5.1.6\Utilities\PathTracer.cs:647
at Pathfinding.PathTracer.UpdateEnd (UnityEngine.Vector3 position, Pathfinding.PathTracer+RepairQuality quality, Pathfinding.Util.NativeMovementPlane movementPlane, Pathfinding.ITraversalProvider traversalProvider, Pathfinding.Path path) [0x00001] in .\Library\PackageCache\com.arongranberg.astar@5.1.6\Utilities\PathTracer.cs:317
at Pathfinding.ECS.JobRepairPath.Execute (Unity.Transforms.LocalTransform& transform, Pathfinding.ECS.MovementState& state, Pathfinding.ECS.AgentCylinderShape& shape, Pathfinding.ECS.AgentMovementPlane& movementPlane, Pathfinding.ECS.DestinationPoint& destination, Unity.Entities.EnabledRefRW`1[T] readyToTraverseOffMeshLink, Pathfinding.ECS.ManagedState managedState, Pathfinding.ECS.MovementSettings& settings, Unity.Collections.NativeList`1[T] nextCornersScratch, Unity.Collections.NativeArray`1[System.Int32]& indicesScratch, Unity.Collections.Allocator allocator, System.Boolean onlyApplyPendingPaths) [0x0009c] in .\Library\PackageCache\com.arongranberg.astar@5.1.6\Core\ECS\Jobs\JobRepairPath.cs:166
at Pathfinding.ECS.JobRepairPath.Execute (Unity.Entities.ArchetypeChunk& chunk, System.Int32 unfilteredChunkIndex, System.Boolean useEnabledMask, Unity.Burst.Intrinsics.v128& chunkEnabledMask) [0x00103] in .\Library\PackageCache\com.arongranberg.astar@5.1.6\Core\ECS\Jobs\JobRepairPath.cs:122
at Pathfinding.ECS.JobRepairPath.Unity.Entities.IJobChunk.Execute (Unity.Entities.ArchetypeChunk& chunk, System.Int32 unfilteredChunkIndex, System.Boolean useEnabledMask, Unity.Burst.Intrinsics.v128& chunkEnabledMask) [0x00000] in <18f1e63f002e4955adae22c3c0d33547>:0
at Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].ExecuteInternal (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x0013f] in .\Library\PackageCache\com.unity.entities@1.2.3\Unity.Entities\IJobChunk.cs:420
at Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].Execute (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x00001] in .\Library\PackageCache\com.unity.entities@1.2.3\Unity.Entities\IJobChunk.cs:363

Here’s how I workaround the problem:
Change PathTracer.nnConstraint.graphMask to the traversable graphs via reflection when creating an agent, because I did not find a public API for this. I would like to get rid of this reflection.

I use only Pathfinding.ECS and do not use FollowerEntity. So the stack trace for FollowerEntity may be different. But I have verified that the same problem exists with FollowerEntity.

Just to verify for the bug request, this is happening on the latest release, 5.1.6? If not, let us know what version you’re on as well :+1:

Yes, it’s on version 5.1.6

1 Like

Gotcha, thanks for that info. Brought this to aron’s attention :+1: Thanks for submitting the issue!

1 Like

This was indeed a bug.
I’ll include a fix in the next update.

1 Like