Support Forum

Recast graph loses penalty after NavmeshCut

Hi,

My recast graph loses its penalties applied through an GraphUpdateScene after an object cuts into the graph. What would be the correct way to re-apply the penalties after a cut.
I found the OnEnableCallback on the NavmeshClipper however this is a private event.

Hi

Yes, unfortunately there is no way to keep penalties after a navmesh cut as the graph can have changed in arbitrary ways.

I would recommend that you use tags (because applying a tag multiple times to the same region is ok, in contrast to penalties which will accumulate). To get an event when graph updates are done you can make a script inherit from the GraphModifier class, and then override the OnGraphsPostUpdate method.

class MyType : GraphModifier {
    public override void OnGraphsPostUpdate () {
    }
}

Hey,

Reapplying the tags in OnGraphsPostUpdate invoke OnGraphsPostUpdate causing an infinite loop.

Oh, right… I suppose you could call (AstarPath.data.recastGraph as IUpdateableGraph).UpdateArea(guo) directly, that will not cause the callback to be called. And since you are only updating penalties it should be fine.

Hi, I’ve tried the approach described here, but I find it unsatisfactory for the following resons:

  1. It requires me to rebuild the GraphUpdateObject manually, which is essentially copying the contents of Apply method and that can lead to frustrating bugs after updating the plugin as the code desynchronises.
  2. When updatePhysics is set to true it crashes.
  3. Not that much of an issue, but the GraphUpdateScene editor doesn’t work on children. It can be fixed by just overriding the original editor, but still.

Instead of that all, couldn’t there be just another flag “Apply On Graph Update”?