A* Pathfinding Project

Graph Areas not updated when OnGraphsUpdated() is called


#1

Hi there,

I have a callback that is hooked up to AstarPath.OnGraphsUpdated. Whenever I move one of my graph blocker objects and update the grid graph such that multiple areas should be created where only one existed before, I still only see one area when I look in my OnGraphsUpdated callback. If I recalculate the graph again, it properly updates. Does area updating happen after OnGraphsUpdated is called? If so, what would be the best way to hook into when everything involving a graph update is totally complete? I used to do a FlushGraphUpdates() call after I moved my items around/destroyed them, but I have a lot of units pathing and it was tanking my frame rate pausing all of the pathing threads, so I switched to the OnGraphsUpdated callback.

Thanks!
Eric


#2

Hey Eric,

You can read more about the callbacks in the Graph Modifier Base class: https://arongranberg.com/astar/docs/class_pathfinding_1_1_graph_modifier.php

Perhaps the OnGraphsPostUpdate would work better for you.

Kind regards,
Wolf


#3

Thanks Wolf, that worked perfectly for me!


#4

Actually it didn’t work, other code I had was forcing a flush. Looking at WorkItemProcessor, the flood fill is definitely happening before the PostUpdate event is triggered:

EnsureValidFloodFill();

Profiler.BeginSample(“PostUpdate”);
if (anyGraphsDirty) GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate);
Profiler.EndSample();

Yet, when I hook into that event and check the area of two nodes that were in different areas but should now be in the same area, the areas are still different. If I wait a few frames and check again, the areas match


#5

GraphUpdateProcessor.ProcessGraphUpdates() is the culprit. It calls GraphModifier.TriggerEvent(GraphModifier.EventType.PostUpdate) without regard to EnsureFloodFill happening. I don’t think the event should be triggered in that method.


#6

I agree that this should be labeled as a bug.
We’ll have to wait for Aron his return.