ArgumentOutOfRangeException Occurs When Setting NodeLink2.enable = true

  • A* version: 5.4.5
  • Unity version: 6000.2.6f2

Hello,

I’m experiencing an intermittent issue when setting NodeLink2.enable = true.

Sometimes, right at the moment the property is set to true, an ArgumentOutOfRangeException occurs. After this exception happens, the FollowerEntity pauses briefly, and then it starts using the NodeLink2 after the delay. This causes an unintended stop in gameplay.

Error example:

ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: partIndex
Pathfinding.PathTracer.GetLinkInfo (System.Int32 partIndex) (at ./Packages/com.arongranberg.astar/Utilities/PathTracer.cs:1694)
Pathfinding.ECS.TraverseOffMeshLinkSystem.NextLinkToTraverse (Pathfinding.ECS.ManagedState state) (at ./Packages/com.arongranberg.astar/Core/ECS/Systems/TraverseOffMeshLinkSystem.cs:69)
Pathfinding.ECS.TraverseOffMeshLinkSystem.StartOffMeshLinkTraversal (Unity.Entities.SystemState& systemState, Unity.Entities.EntityCommandBuffer commandBuffer) (at ./Packages/com.arongranberg.astar/Core/ECS/Systems/TraverseOffMeshLinkSystem.cs:57)
Pathfinding.ECS.TraverseOffMeshLinkSystem.OnUpdate (Unity.Entities.SystemState& systemState) (at ./Packages/com.arongranberg.astar/Core/ECS/Systems/TraverseOffMeshLinkSystem.cs:42)
Pathfinding.ECS.TraverseOffMeshLinkSystem.__codegen__OnUpdate (System.IntPtr self, System.IntPtr state) (at <0cd40b5daa28465da9e65c4e14d13f5e>:0)
Unity.Entities.SystemBaseRegistry+<>c__DisplayClass9_0.b__0 (System.IntPtr system, System.IntPtr state) (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/SystemBaseRegistry.cs:249)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/Stubs/Unity/Debug.cs:17)
Unity.Entities.<>c__DisplayClass9_0:b__0(IntPtr, IntPtr) (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/SystemBaseRegistry.cs:253)
Unity.Entities.UnmanagedUpdate_00001677$BurstDirectCall:wrapper_native_indirect_0x44dd7adf0(IntPtr&, Void*)
Unity.Entities.UnmanagedUpdate_00001677$BurstDirectCall:Invoke(Void*)
Unity.Entities.WorldUnmanagedImpl:UnmanagedUpdate(Void*)
Unity.Entities.WorldUnmanagedImpl:UpdateSystem(SystemHandle) (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/WorldUnmanaged.cs:891)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ComponentSystemGroup.cs:717)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ComponentSystemGroup.cs:687)
Pathfinding.ECS.AIMovementSystemGroup:OnUpdate() (at ./Packages/com.arongranberg.astar/Core/ECS/Systems/AIMovementSystemGroup.cs:211)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/SystemBase.cs:418)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ComponentSystemGroup.cs:723)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ComponentSystemGroup.cs:681)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/SystemBase.cs:418)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at ./Library/PackageCache/com.unity.entities@e581b903be8e/Unity.Entities/ScriptBehaviourUpdateOrder.cs:523)

It doesn’t occur every time, but it happens frequently enough to be noticeable.

Could you please check what might be causing this issue or suggest a workaround?

Thank you!

Recreating this in a scene right now. Wanted to ask you when were you setting enabled to true? Right when the agent is about to traverse the link?

In our game, we have a unit that places a ladder.
When the ladder is placed, we set NodeLink2.enable = true.

Right after the ladder is placed, the unit immediately starts climbing the ladder.
At this moment, sometimes an ArgumentOutOfRangeException is thrown.
When the exception occurs, the unit pauses briefly and then starts moving again.

There are cases where it works correctly without any issue, but I want to prevent this situation from happening entirely.

And the ladder has the NodeLink2 component then? When it’s “placed” is any scanning done? Or are the NodeLink2 components already in place and they just “put a visual representation down and use it”? Basically, does anything in the graph change, or is an existing NodeLink2 just enabled when needed?

We keep the existing NodeLink2 components disabled, and when a ladder is placed we just enable the corresponding NodeLink2.
There is no change to the whole graph — we are simply activating a pre-existing NodeLink2.

Are you using the enabled from MonoBehaviour? NodeLink2 doesn’t have an enable/enabled property on it’s own. I didn’t notice this until trying to recreate it myself and realized I had only set the enabled state of the component itself. Are you disabling and enabling this through custom logic for your off-mesh link? Not sure, maybe I’m just missing something here.

I created a custom component that handles my off-mesh link logic, and I have a NodeLink2 component attached to the same GameObject.

From that off-mesh link logic component, I toggle the NodeLink2 component’s enabled state when the ladder is placed.

So when I tried a very simplified version of this, if I had my agent go towards a destination that’s only reachable through an offmesh link, they would not make it there at all if the link component was disabled. I’d enable it and they’d need a new path to use the link. So I’m confused how your agent is getting the path to the destination if the off mesh link is disabled. That’s also how I figured out there was no NodeLink2.enabled field, just MonoBehaviour.enabled (or, more accurately a bunch of things that inherit from VersionedMonoBehaviour but that’s not relevant)

A description of what’s going on there or some video may help.