Can't get layered grid graph to work with voxel world


I’m working on a project that use a voxel world alá Minecraft for it’s terrain . I’m trying to use the layered grid graph for pathfinding but I’m afraid I don’t understand how to get it working.

If you look at the screenshot below I have some terrain in which I’ve dug a hole and run a scan. But it seems everything is set as not walkable.

These are my settings:

I’ve tried changing the collider values around and if I offset by > 0.5 I do get a grid on the first layer but nothing below.

My terrain starts at y=0 but I’m guessing the layered grid graph handles objects positioned below origin(?)

Any help is greatly appreciated.



The graph will only check for collisions above the base of the graph. So you should set the ‘Center’ y coordinate to the lowest point that your level can reach. The graph will check all y coordinates between the base of the graph up to the base up the graph + [Graph Settings -> Height Testing -> Ray Length].

The optimal setup depends on how your world is constructed, but I think the issue you are facing right now is that you have included the ground in the collision testing layer mask. This will cause the ground to be identified as an obstacle and therefore all nodes will be unwalkable. You will probably want to remove the ground from that layer mask.
Depending on how your world is constructed you may want to leave it in the layer mask but instead increase the ‘offset’ value until the nodes become walkable, but to start with I think you should remove it.

Hi and thanks for the quick response!

I adjusted the center and it now generates areas for the lower levels. Unfortunately I’ve encountered another problem.
The game lets you modify the terrain as in Minecraft and I can’t get the grid graph to generate areas below other blocks.

I assume this is because I’ve configured a the capsule collider to a height of 2 and it collides with the terrain above it.
I still do collision checks on the ground layer because I need to make the volume of the terrain an obstacle to prevent the grid graph from generating walkable nodes in areas filled with blocks.

Each block is 1 unit high so I changed the height of the capsule collider to 0.5 (offset 0.3) thinking that it would be short enough to not hit the ceiling above. This made all the grid nodes on each layer walkable though.

Is what I’m doing possible with the layered grid graph or am I better of writing a custom graph?


Ah. You have boxes everywhere even if they are covered. From some experience in implementing voxel engines I think you will have to optimize that at some point if you are going to want to handle moderately large worlds.

As it is right now I cannot think of a way to distinguish between the two cases using the information that the layered grid graph has unfortunately.

You could create a custom graph as a subclass of the Layered Grid Graph.
Of particular interest is the SampleCell method. Right now it is not virtual, but you can easily make that change (and I will likely make it virtual in the next update too).
If you override the SampleCell method you should be able to get complete control over how the nodes are generated.

public class MyVoxelGraph : LayerGridGraph {
    protected override LinkedLevelNode SampleCell (int x, int z) {
          // ...

The SampleCell method returns a linked list of LinkedLevelNode instances. Each instance will be converted to a node.

class LinkedLevelNode {
	public Vector3 position;
	public bool walkable;
	public RaycastHit hit;
	public float height;
	public LinkedLevelNode next;

To make sure the graph shows up in the inspector you will also have to add this class

[CustomGraphEditor(typeof(MyVoxelGraph), "Voxel Graph")]
public class MyVoxelGraphEditor : LayerGridGraphEditor {


Sorry, I should’ve explained it better.

The terrain is made out of chunks of 30x1x30 (x y z) blocks. Each terrain chunk is one mesh and it only draws the sides that are next to non occupied space. It generates chunks around the player as he/she moves around and I move the grid graph accordinly and run scans when necessary. All this works well except for the overhang stuff I explained in my previous post.

I guess the problem still stands though. I’ll have a look at overriding the graph with the info you posted :slight_smile:

Tack så mycket :wink:


I made a voxel graph like you suggested and replaced the collision check with a custom method and it seems to be working :slight_smile:

Thanks again!

1 Like