Know which GraphUpdateObjects was updated in "OnGraphsUpdated" when having multiple GUO

First of all, I’m new to this forum and I would like to thank you to all the forum’s users for your constant help.

And specially, I would like to thank Aron Granberg for creating this plugin and the Documentation.

My team and I had been working on a game using Unity’s NavMesh for a year when we found out this existed we were so relieved since most of the problems we had with NavMesh banished really quickly.

The plugin works wonders for an RTS-like game.


I have the following situation in my project:

  • We use colliders to set obstacles like boxes and rocks.

  • We already use penalties to deal with the interactions between moving units. Our units have penalties in their surrounding nodes, that’s why we can’t deal with obstacle by using penalties.

  • Once those get destroyed we update the graph with GraphUpdateObject with the bounds of the soon to be destroyed object.

  GraphUpdateObject guo = new GraphUpdateObject(boundsBounds);
  guo.updatePhysics = true;
  AstarPath.active.UpdateGraphs (guo);
  • Normally those objects are destroyed because a nearby melee unit attacks them. So we have to update the penalties by using a method we created that takes the max distance where to update and the position where the obstacle was:
  float fDistance = Mathf.Max(obstacle.collider.bounds.size.x, obstacle.collider.bounds.size.z)*2;
  Vector3 v3ObstaclePosition = obstacle.transform.position;
  UpdateAllUnitsAtDist(fDistance , v3ObstaclePosition);
  • We can store these values in a structure that contains distance, position and guo. This way we know which destroyed obstacles are still pending.

We can know when to update the area where the obstacle standed by using OnGraphsUpdated but not which GraphUpdateObstacle was updated for.

We would like to avoid using FlushGraphUpdates since we can have multiple obstacles being destroyed at the same time and things can get pretty costly

AstarPath.active.FlushGraphUpdates ();

Is there any way to find for which GraphUpdateObstacle was OnGraphsUpdated called?

Thanks in advance!

Got it working by using trackChangedNodes

public void OnUpdateAStar(AstarPath astarPath)
{
    for (int i = listUpdateStructure.Count-1; i >= 0; i--)
    {
        if (listUpdateStructure[i].guo.changedNodes != null && listUpdateStructure[i].guo.changedNodes.Count > 0)
        {
          UpdateAllUnitsAtDist(listUpdateStructure[i].fDistance, listUpdateStructure[i].v3ObstaclePosition);
          listUpdateStructure.RemoveAt(i);
        }
    }
}

Hi

Thank you for your kind words :slight_smile:
OnGraphsUpdated is only called once per batch of updates, so there might have been several updates that have been performed for each time that OnGraphsUpdated is called.

1 Like