How to tell which graph(s) a collider is currently overlapping

Sorry to bother, but I couldn’t find an answer to this in the doc.

I’m trying to find a reliable/performative way to tell what 2D grid a seeker is in the bounds of in a scene with multiple grids. I could run a check that takes the bounds and positions of each grid a few times a second and make a list of seekers inside of it, but that seems less than optimal

Hi

You could find the closest node to each agent and check which graph it is on:

var node = AstarPath.active.GetNearest(agent.position).node;
var gridGraph = node.Graph as GridGraph;

That wouldn’t tell me when an seeker is not on any grid right? I have a grid attached to multiple players, and I want to add a new behavior for my AI when it is out of bounds of any grid

You can check if the closest point is far away:

var nearest = AstarPath.active.GetNearest(agent.position);
if (Vector3.Distance(agent.position, nearest.position) > 10) {
    // Far away from any grid
}

That might work, thank you! Also this has to be the best plugin in Unity, great work!

1 Like