Mark nodes as unwalkable based on Height

Is there a way to mark nodes as unwalkable depending on height ? I have a problem where the seeker will think the nearest walkable node is on top of the wall like in the pic above. Then there is no path from top of wall to destination.

Hi

Since you say “wall”, I think the better solution is just to mark all walls as being obstacles (put them in a layer included in the Collision Testing mask). That will prevent any walkable nodes from being generated on top of it.

You can also reduce the “Ray Length” in the grid graph settings (Height Testing) to avoid nodes being placed on top of large obstacles.
There is no way to do exactly what you are asking for without some scripting.

Unfortunately, I can’t go in and mark all the walls because the level designer sets up stuff like that and I don’t want to burden him with that right now. What if I iterate through all nodes and check their y position and mark the ones too high as unwalkable. ? Is there a way to cast from Int3 to world Vector3 position ? GetNodes function specifically says not to change anything in the graph structure though.

Hi

An Int3 has an explicit cast to Vector3. So just (Vector3)node.position will work.

Sure, you can do that.
The easiest is to create a custom graph update object since then the system will handle all details like pausing pathfinding threads and updating other pathfinding data structures.
If you do it without a graph update object, you need to wrap it in some other calls to make sure you do not try to update the graph while pathfinding is running (possible in another thread) at the same time as that could cause bad stuff to happen.

`
using Pathfinding;
public class MyGUO : GraphUpdateObject {
float ylimit = 5;
public MyGUO ( Bounds bounds ) {
this.bounds = bounds;
// Disable regular recalculation of the graph
updatePhysics = false;
}
public override Apply (Node node) {
if ( ((Vector3)node.position).y > ylimit ) {
node.walkable = false;
}
}
}

void Start () {
// Update with some large bounds which you are sure covers the entire graph
AstarPath.active.UpdateGraphs (new MyGUO ( new Bounds ( Vector3.zero, Vector3.one*100000));
}
`

Note: I haven’t tested the above code, but I think it will work.

I essentially did the same thing. But in a much less generic way without graph update objects. I’ll change to this way. Thanks !