- A* version: [5.3.3]
- Unity version: [2022.3.55f1]
Hi everyone,
I’m working on a VR project in Unity (using A* Pathfinding Project Pro) and have been running into persistent memory leaks related to pathfinding, particularly with Recast Graphs. The leaks seem to occur during scene transitions and gameplay, especially when enemies are actively chasing the player.
My Setup:
- Unity Version: 2022.3.55f1
- A* Pathfinding Version: Pro version (latest update)
- VR Framework: Unity XR Toolkit (using Valve Index for testing)
- Pathfinding Graph: Recast Graph (planning to use procedural generation in the future)
- Enemy Movement: Custom
EnemyAI
script using Seeker and Path components for navigation.
Issue Details:
- I’m getting persistent memory leaks from allocations related to
Pathfinding.BinaryHeap
,PathHandler
, andPathProcessor
. - The leaks often occur when the enemy requests paths frequently or when an enemy object is destroyed.
- Using Unity’s Profiler, I’ve tracked consistent memory leaks with the following message:
A Native Collection has not been disposed, resulting in a memory leak.
Leak Detected: Persistent allocates multiple allocations from Pathfinding.BinaryHeap.cs
- I also tried switching to a Grid Graph temporarily, but similar issues persisted.
What I’ve Tried:
-
Ensured that paths are correctly claimed and released:
if (path != null)
{
path.Release(this);
} -
Cancelled ongoing path requests when stopping enemy movement or destroying the object.
-
Disabled unnecessary threads via AstarPath settings.
-
Verified that the
Seeker
component isn’t issuing multiple simultaneous requests.
Error Logs: Here’s a typical leak stack trace:
Found 1 leak(s) from callstack:
Pathfinding.BinaryHeap:.ctor (int) (at ./Packages/com.arongranberg.astar/Core/Collections/BinaryHeap.cs:94)
Pathfinding.PathHandler:.ctor (Pathfinding.GlobalNodeStorage,int,int) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathHandler.cs:192)
Pathfinding.PathProcessor:SetThreadCount (int,bool) (at ./Packages/com.arongranberg.astar/Core/Pathfinding/PathProcessor.cs:99)
AstarPath:InitializePathProcessor () (at ./Packages/com.arongranberg.astar/Core/AstarPath.cs:1202)
Questions:
- Is there a best practice for managing path memory when using the Recast Graph with frequent enemy pathfinding requests?
- Would switching to a Grid Graph for static scenes help with memory management?
- Is there an internal method within A* Pathfinding Pro for clearing or disposing of old path data effectively?
- Are there specific Astar settings I should tweak for better memory management in a VR environment?
Any help or guidance on this would be greatly appreciated. If anyone has experienced similar issues with A* Pathfinding in Unity VR, I’d love to hear how you solved it.
Thanks so much for your time!