Innaccurate navmesh update when changing walkability in runtime

Pertains to objects both with box or mesh collider, both grid and recast graph. Expected result: the road becomes unwalkable. Observed result: objects around become unwalkable, the road not. I would appreciate fast support, paid version.

Movie:

The movie works, just not displayed here, please use RMB->SaveAs

Hi

I don’t quite understand what issue you are trying to indicate in the video. Would you mind giving a brief description of what you are trying to do?

Sure. I want to disable walkability on the road (basically using a remade script from examples), it works really ok for most road objects, but for some reason for this one it fails.

I am a noob when it comes to A* Pathfind so maybe there is a better approach. My end goal is to have roads which walkability I can alter, and also crossings. It almost works, apart from this issue.

Would you mind posting the script here?

public class AStarTagSetter : MonoBehaviour
{
[SerializeField]
private int tag = 1;
[SerializeField]
private bool modifyWalkability = false;
[SerializeField]
private bool setWalkability = false;
[SerializeField]
private int penaltyDelta = 0;

    private Bounds bounds;

    public void OnEnable()
    {
        bounds = GetComponent<Collider>().bounds;

        GraphUpdateObject guo = new GraphUpdateObject(bounds);

        // There are only 32 tags
        if (tag > 31) { Debug.LogError("tag > 31"); return; }

        guo.modifyTag = true;
        guo.setTag = tag;
        guo.updatePhysics = false;

        guo.modifyWalkability = modifyWalkability;
        guo.setWalkability = setWalkability;

        guo.addPenalty = penaltyDelta;

        AstarPath.active.UpdateGraphs(guo);
    }
}

Btw. An easier way is probably to use the current beta version add add the new grid graph rule named “Per Layer Settings”. It allows you to just switch the layer of the road collider and have the surface become completely unwalkable. See Documentation

ok are bounds the problem?

Thank you will check that!

That script will update all nodes within an axis aligned bounding box. This is probably not what you want since the road is rotated. You can assign the guo.shape field to specify exactly where it should update the graph, but if possible I think you should try out the beta version. When using that you can just change the layer of the object and then run AstarPath.active.UpdateGraphs(collider.bounds) and it will recalculate the nodes within the road to match its new layer.

Thank you very much for fast support. I will discuss the beta approach, the decision is not mine to make.
As to guo.shape - is there a method to compute the shape from mesh filter, for instance, or do I need to make one?

Best regards

There is no built-in way to compute the shape I’m afraid.

No worries, thank you for support.