How to force update the grid graph or procedural graph mover?

Hey all, kind of a nooby question but I feel at a loss. After updating objects that should change how my grid graph is scanned and thus making some nodes walkable or not, simply calling _gridMover.UpdateGraph(); does not update the changed nodes (tried both sync and async). I breakpointed inside my custom grid rule and it never gets hit after making this call. I also tried AstarPath.active.ScanAsync. Is there a really obvious method I’m missing that can help me do this?

Hi

The ProceduralGraphMover makes great effort into only recalculating the nodes that need to be recalculated after it has moved the graph. So it will only recalculate the nodes around the borders of the graph. If you have changed something in a grid rule you’ll need to do a regular graph update: AstarPath.active.UpdateGraphs(bounding box). Or re-scan the whole graph if your changes will affect everything (AstarPath.active.Scan()).

Also keep in mind that grid graph rules have an internal hashing function that avoids running some parts of it unless the settings have changed. Call rule.SetDirty() to invalidate it.

1 Like

thanks for responding so quickly, the bounds update wasnt working as expected, neither the async update, but im happy i got it working at all!

here’s the code i used hoping it helps someone else:

            var active = AstarPath.active;

            //active.UpdateGraphs(bounds); // doesnt work for some reason
            active.Scan();

            if (active != null && active.graphs.Length > 0
                && active.graphs[0] is GridGraph grid)
            {
                // https://forum.arongranberg.com/t/how-to-force-update-the-grid-graph-or-procedural-graph-mover/15129/2?u=gooby
                var rules = grid.rules.GetRules();
                foreach ( var rule in rules )
                {
                    rule.SetDirty();
                }
            }

That probably works because it calls rules[i].SetDirty() under the hood. I’d recommend calling that directly instead of disposing the unmanaged data, as this could cause crashes if an async scan was running at the same time.

1 Like

i missed the GetRules method :sweat_smile: thanks for pointing that out, updated the previous code