How to use gridGraph.SetDimensions on two existing gridGraphs in code


i have a question that is hopefully fairly easy to answer, but I’ve been hanging on to it for some time now.
In our 2D game, we generate multiple small rooms (like in the binding of isaac).
When entering a new room, i move the gridGraph to the middle of the new room and change the width and depth of the nodes to the size of the room with this code:

var gg =; = room.transform.position;
gg.SetDimensions(room.GetRoomWidth(), room.GetRoomHeight(), 0.8f);;

This works fine.

Now we added a second enemy type that can fly over holes.
For this to work, i added a second grid graph with a different layer mask.
I named the first graph “Walk” and the second “Fly”.
With the code above, i only change the values for the “Walk” grid.
I have already tried a lot to get the grid graph of “Fly” but unfortunately I am not successful.
something like:

foreach (var item in
    Debug.Log(;, room.GetRoomHeight(), 0.8f);

writes “Walk” and “Fly” in the console, but it only changes the values of “Walk”.

Even if i use: => == "Fly");

it only changes the values of “Walk”.

I hope you can help me with this problem :slight_smile:

Hi, room.GetRoomHeight(), 0.8f);

This should be

var graph = item as GridGraph;
graph.SetDimensions(room.GetRoomWidth(), room.GetRoomHeight(), 0.8f);

Alternatively you could save the gg variable you used when creating the graph.

The active field just refers back to the global AstarPath instance.

1 Like

It works.
Thanks a lot :slight_smile:

1 Like