Clear work items queue / quit to main menu

When I quit my game to the main menu, a whole bunch of errors pop up relating to a missing graph for a graph update from a queue. I am assuming the work item queues are still full of updates ready to process, but then error out after I have cleared the graphs.

What’s the best practice way to clear the queues, I believe the relevant ones are on GraphUpdateProcessor?




Do you have any full stack traces for this?

Yep, this is the stack trace:

Graph doesn’t exist
UnityEngine.Debug:LogError (object)
Pathfinding.AstarData:GetGraphIndex (Pathfinding.NavGraph) (at Assets/AstarPathfindingProject/Core/AstarData.cs:741)
Pathfinding.RecastGraph:Pathfinding.IUpdatableGraph.UpdateArea (Pathfinding.GraphUpdateObject) (at Assets/AstarPathfindingProject/Generators/RecastGenerator.cs:526)
Pathfinding.GraphUpdateProcessor:ProcessGraphUpdatesAsync () (at Assets/AstarPathfindingProject/Core/Misc/GraphUpdateProcessor.cs:348)
System.Threading.ThreadHelper:ThreadStart ()



Strange. It should be forcing all work items to complete before the AstarPath component is destroyed.

You could try updating to the beta version. The whole graph update system has been reworked in the beta, so it is likely that it has been fixed already.

Thanks, I’ll look into the beta - in the meantime is there a way to manually clear the queue to avoid processing the items at all? I want to avoid a delay in returning to the menu if possible

It’s not possible to clear the queue at the moment, I’m afraid.

OK so I managed to reach a similar outcome just by attaching the ‘Pathfinding’ script to a prefab that I create on new / load game and destroy anytime I quit to main menu. This seems to be working, though the old graphs still show up in editor mode in the main menu but seem to disappear when new graphs are scanned.

@aron_granberg is there anything dramatically wrong with this approach I should be aware of (memory leaks, critical failures down the line somewhere)?

1 Like

Seems like an ok approach.

Great, thank you - this seems to be working ok