Update GridGraph because of rising unwalkable terrain

Hi :),

I’m currently stuck at trying to get a grid graph to update properly, when altering the terrain.

The scenario:

There are currently two layers for pathfinding ‘walkable’ and ‘unwalkable’.

I’m having an island (on the walkable layer) surrounded by lava (on the unwalkable layer). The island is built by using the normal Unity terrain. The lava is just a plane with a box-collider.

Situation before updating the graph.

The GridGraph is calculated just fine.

Now if I’ raising the Lava via code (I need to parse the parameter, because this is called via the ingame console):


/// Raises the lava by a specified amount.

/// The amount in meters the lava will be raised in world-space.
private void RaiseLava(string raiseLavaAmount)
this.transform.position += Vector3.up * Mathf.Abs(float.Parse(raiseLavaAmount));
    Bounds bounds = this.collider.bounds;

    GraphUpdateObject guo = new GraphUpdateObject(bounds);
    guo.modifyWalkability = false;
    guo.updateErosion = false;
    guo.updatePhysics = true;


The nodes on the lava get walkable:

Situation after updating the graph.

When rescanning the graph at runtime (AstarPath.active.Scan()) I get the same result. Raising the lava in the editor when not running the game and scanning the terrain works fine.

Here are the settings of the AStar pathfinding object in the scene:

AStar settings.

The ‘Mask’ is configured to contain the ‘walkable’ and ‘unwalkable’ layer.

I’m sure I’m doing something wrong here, but I have currently no idea what that could be.
Any help is greatly appreciated.

If you get the same result by running Scan during runtime, then something is different in the runtime. The Scan logic is exactly the same in the editor as when playing the game.
Check that the layers for the lava is still correct during runtime.

Also, is it perhaps so that the lava is positioned at Y=0 at the start?
If so, it might not be hit by the raycast when scanning initially; which would make the nodes unwalkable due to ‘Unwalkable when no ground’. But when it rises it would get hit and other logic would kick in.

Figured it out… I’m using a mesh-collider (configured as a trigger) for a rts-style-controlling logic.

Since it’s on the default layer I expected the graph-update to ignore it when updating the graph (since UpdatePhysics is set to true, so it should take the settings from the GridGraph for collision and height testing).

This collider seems to mess with the graph-update at runtime. Maybe because it’s configured as a trigger.

Setting the y-position of the grid-graph to 1 solved it (since the y-position of the mesh-collider is a y = 0).

Thanks for the help :).

Try changing the Unity Project Settings -> Physics Settings -> Raycast Hits Triggers option.

Interesting discussion Angstr0m, and thank you to Aron_Granberg for his answer. I have a similar feature and learn a lot from this reading.

I’m not already very familiar with the “UpdateGraphs” method, but for this case, wasn’t it more optimized to simply turn ON or OFF the walkability of each node by testing its Y value against the lava Y value ?
If the lava is continually raising, wasn’t it very expensive to call all the Raycast in “UpdateGraphs” ?

Yes, that is a more performant option, esp. if the lava is only rising and not lowering.