Is there a way to get all nodes covered by a GraphUpdateScene component?

I want to look through all nodes and check if the position is on top of water or not, and if it is, set the tag to water/land.

Atm I cannot find any way to get the nodes covered by a GraphUpdateScene component, all I can do is:

myGus.setTag = MyTag;

But this sets the tag for all nodes covered by the GraphUpdateScene.

Hi

If you are using a grid graph, you can use:

var graphUpdate = GetComponent<GraphUpdateScene>();
var gg = AstarPath.active.data.gridGraph;
var nodes = gg.GetNodesInRegion(graphUpdate.GetBounds());

This will only work if you are just using a bounding box for your GraphUpdateScene, though, not for any more complex shapes.

Thank,

I think Ill just my own little bounding box gizmo creator thing and add a script to that which can set tags to how u do above, seems cleaner.

1 Like


image

Hi can you exaplin what you mean by bounding box? I tried gg.GetNodesInRegion(graphUpdate.GetBounds()); with this bounding box and it didnt find any nodes. Am I setting it up wrong? The box works fine for setting/clearing tags using graphUpdate.setTag

Hi

When a graph update is done, it will project the bounds on the graph’s plane first. This means the ‘up’ direction of the bounds (y-axis if you are working on a 3D game) doesn’t matter. The GetNodesInRegion method does take the y coordinate into account, though.

The beta version has changed this so that graph updates also check the y coordinate, to make it consistent.

Make sure that the bounding box actually contains the nodes you want to update along all axes.

Okay, so short answer give the bounding box a value on the y-axis so it encapsulates the nodes properly?

Yes. That is correct.

Hmm darn, that didnt do it:

image

public void Test()
        {
            for (int i = 0; i < tagSurfaces.Length; i++)
            {
                var graphUpdate = tagSurfaces[i];
                var gg = AstarPath.active.data.gridGraph;
                var nodes = gg.GetNodesInRegion(graphUpdate.GetBounds());

                for (int j = 0; j < nodes.Count; j++)
                {
                    var node = nodes[j];
                    Debug.Log("Position " + node.position + " is at grid pos: " + gridPos + ". Is water: " + infoCell.isWater + ". Is bordering water: " + infoCell.isLandNeighboringWater);
                }
            }
        }

Are you sure this bounding box actually contains the nodes you are interested in?

1 Like

I just did a more controlled test with only the bounding box and the code does work, the issue is somewhere else. Ill figure it out, thanks a ton!

The issue turned out to be rly weird. the only way it will work is if I at some point enable Gizmos. But if I play and never turn on Gizmos, it always returns empty?

Is there something in ur asset that remains “dormant” until u render gizmos or something that is called when gizmos are enabled?

Can also confirm that I didnt need to make it a “box”, the first version where y=0 works but not until I turn on gizmos.

Hmm, indeed. I think that GetBounds might have returned an empty bounds if the convex option was disabled, and gizmos were never rendered. I’ll fix this in the next beta release.

Thank you, any idea when that is?

Not at the moment. But definitely not too far into the future. In the meantime, as a workaround, you can call graphUpdateScene.RecalcConvex() before you call GetBounds.

thats seems to work, thanks! :slight_smile:

1 Like