[Bug] ObjectDisposedException when I disable AstarPath or gameObject

A* version: 5.3.7 (pro)
Unity version: 2022.3.62f1
This bug is actively preventing me from building the project unless I use the attached workaround

Reproduction:

  1. Create a GameObject and attach the AstarPath script to it.
  2. Disable the script or the gameObject
    a. You can do this in the inspector without the game running
  3. Check the console and you’ll see the ObjectDisposedException exception.

Workaround:

  • Try/catch around the offending area (NavmeshEdges.cs:31), where it disposes of the allocationLock
    • I’d like to avoid this, hence the ticket

Additional notes:

  • I don’t actively disable this script or anything, it throws when I swap scenes
  • It’s preventing me from building without the workaround
  • I’ve tried downgrading versions and best I can tell, this issue begins with all of 5.3.x
ObjectDisposedException: Cannot access a disposed object.
Object name: 'The NativeReference is already disposed.'.
Unity.Collections.NativeReference`1[T].CheckNotDisposed () (at ./Library/PackageCache/com.unity.collections@1.5.1/Unity.Collections/NativeReference.cs:349)
Unity.Collections.NativeReference`1[T].Dispose () (at ./Library/PackageCache/com.unity.collections@1.5.1/Unity.Collections/NativeReference.cs:128)
Pathfinding.NavmeshEdges.Dispose () (at ./Library/PackageCache/com.arongranberg.astar@5.3.7/Core/Misc/NavmeshEdges.cs:31)
Pathfinding.HierarchicalGraph.OnDisable () (at ./Library/PackageCache/com.arongranberg.astar@5.3.7/Core/Pathfinding/HierarchicalGraph.cs:110)
AstarPath.OnDisable () (at ./Library/PackageCache/com.arongranberg.astar@5.3.7/Core/AstarPath.cs:1348)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Hi

Upgrading your collections package will resolve this.
In the next update I’ll include a workaround for old versions of the collections package.

1 Like

That did it, thank you!