GridGraph: Update/Set Mask at runtime

Hello, I have a problem with my GridGraph, it seems that I cannot change the value of its Mask.

[SerializeField] private int maskIndex;
[Button]
public void ShowValue()
{
    GridGraph gridGraph = AstarPath.active.data.gridGraph;
    Debug.Log("Show graphe value : " + gridGraph.collision.mask.value);
    gridGraph.collision.mask.value = 1 << maskIndex;
    Debug.Log("Show graphe value : " + gridGraph.collision.mask.value);
}

my bad code


I use only one graph

Capture d’écran 2024-08-12 173018
result in the console on a graph change via my script

test
layers

changing mask in Pathfinder works perfectly at runtime, but has no influence on my scripts and vice versa as if I retrieved a clone or another graph in my script.

other than that I have no problems and everything works perfectly.

Hi

If you are setting this in edit mode, it’s possible the graph settings are not being serialized afterwards.

You must call:

AstarPath.active.data.SetData(AstarPath.active.data.SerializeGraphs());

after you have modified graph settings via an editor script.

1 Like

Thanks for your answer in fact my problem was elsewhere, there was an ambiguity between mask and heightMask on the naming of the variables in the Pathfinder interface collision.maskHeight it displays “Mask”, I had not looked carefully in “GridGraphEditor”

collision.heightMask = EditorGUILayoutx.LayerMaskField("Mask", collision.heightMask);

Everything is working now !

1 Like