Can't seem to get LayerGridGraph layers to work through rules?

  • A* version: 5.3.7
  • Unity version: 6000.0.23f1

Hello,

I have a LayerGridGraph with a custom rule. No colliders are involved and I pull my placement data from a separate class:

public override void Register(GridGraphRules rules)
{
    this._grid = this.gridHolder.GetComponent<Grid>();
    if (this._grid == null)
        Debug.LogError("GridHolder does not have a Grid component.", this.gridHolder);

    // Register this rule with the grid graph
    rules.AddMainThreadPass(Pass.BeforeCollision, this._EvaluateWalkability);
}

private void _EvaluateWalkability(GridGraphRules.Context context)
{
    if (EntityNavGrid.instance == null)
        return;

    var _nodes = context.data.nodes.positions;
    var _walkability = context.data.nodes.walkable;

    for (int i = 0; i < _nodes.Length; i++)
    {
        Vector3Int _gridPosition = this._grid.WorldToCell(_nodes[i]);
        _walkability[i] = EntityNavGrid.instance.IsWalkable(_gridPosition);

        _walkability[i] = true; // only for demonstration
    }
}

But it won’t evaluate possible nodes from another layer (ie. y != grid center), so the data is always stuck on the ground. I have AstarPath.active.UpdateGraphs(_bounds); where _bounds are the world-space bounds of the (floating) blocks.

Screenshot 2025-05-12 171058

Am I missing something here? Thanks!

Are colliders the only way to add layers and is it not possible to manually add nodes at runtime?

Hi

In addition to setting walkability[i] = true, you must also set a valid position, and you must set nodeNormals[i] = new float4(0,1,0,0); (up).

The arrays are resized based on the physics raycasts, though. I don’t think it’s easily possible to change that from a grid graph rule.
Therefore, if your physics raycasts only detect one layer, then it will resize the arrays to only 1 layer.