Why is Layered Grid Graph limited to 4 connections

Hi There

First big thanks for a awesome project.

I dug into the layered grid graph and was messing around and i changed the graph to have 8 connections and it seems to work fine. Is there a reason for 4 connections?
Performance or memory reasons?

Thanks

1 Like

Hi

Originally it was because there are some situations where the diagonal connection can be ambiguous and it would be equally reasonable to link to two different nodes. However lately I’m thinking that this is a pretty bad reason and if such a case appears it should just make no connection at all (which is also pretty reasonable in those cases). You might find it that it supports 8 connections in a future update :slight_smile:

2 Likes

Awesome thanks for the quick reply. I’ll keep using my hacked 8 direction graph for now and subclass the layered grid graph if I need to update and 8 directions is not supported.
I’ll keep a close eye out for native 8 direction support, would definitely appreciate that built in

Thanks again for a great product

1 Like

Hi guys. I have been struggling with exactly this. Trying to get 8 connections on layered grid graph. Been digging around the layered grid graph like roycon but can’t figure it out. Perhaps you would care to share how you changed it? Or if you could tell me aron that would be great.

So I simply changed the value in Layeredgridgraphgenerator.cs in the ‘public override void open’ function from 4 to 8 and my unit moves in a diagonal direction now. However when I try to move him to the second floor of the building (directly above him) I get two warnings.

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.Path.CanTraverse (Pathfinding.GraphNode node) (at Assets/AstarPathfindingProject/Core/Path.cs:301)

Unhandled exception during pathfinding. Terminating.
UnityEngine.Debug:LogError(Object)
AstarPath:Update() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:897)

Anyway to fix this? Thanks

Hi mat1

Sorry I don’t check here often, when I get a chance I’ll dig out exactly what I changed. I’m guessing I can’t post the whole file tho…

I’ll see what I can do

Thanks Roy, any help would be appreciated.

I am also interested in this, thanks in advance!

Hey Guys

Sorry for the delay

I’m on the latest Asset Store version, not beta
In LayerGridGraphGenerator.cs
I changed any 4’s to 8’s on the following lines, 718, 1120, 1141, 1242
Also in LayerGridGraphEditor.cs
I commented out lines, 12,13,14
And on line 51 changed to NumNeighbours.Eight;

Surprisingly that was it, my test unit then moved diagonally

I did lots of changes to pathfinding in that commit but I’m pretty sure thats all thats needed
I have no idea what other effects it could have or if it effects performance

I guess comment here and we can all work it out if something goes wrong

So I did exactly as you suggested Roycon. Yes my units now move diagonally. However when clicking on a tile(or node) which is on the second floor of the building (i.e a node above a node) I get the same errors as I mentioned above.

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.Path.CanTraverse (Pathfinding.GraphNode node) (at Assets/AstarPathfindingProject/Core/Path.cs:301)

Unhandled exception during pathfinding. Terminating.
UnityEngine.Debug:LogError(Object)
AstarPath:Update() (at Assets/AstarPathfindingProject/Core/AstarPath.cs:897)

Seems that the nodes on the second floor aren’t registering as traversable and it completely bugs out. I can’t even give the unit a new order (in game) when it bugs.

I am bumping this a year later, as it’s still a feature that I’d love to have and it has been said by the developer that maybe could be implemented. Is this planned for the future?

Some time has passed. Are there any updates with 8 connections in layered grid graph? I know that there has to be some limitations, but maybe not as strict as limiting us to 4 connections only?

Yes, in the current beta it is no longer limited to 4 connections.

2 Likes

I just used Using Modifiers

Hi, a couple years have passed, does the current version support 8 connections for layered grids or is there an issue that makes such implementation problematic(or any other reason if it’s still in beta)?

Hi

It’s mostly a case of the beta having been a beta for veery long (mostly due to stability issues in unity’s burst and collections packages, that have only recently been starting to stabilize). The beta is for the most part more robust than the non-beta. So if you need 8-connections, don’t fear using the beta.

1 Like