Why is Layered Grid Graph limited to 4 connections


#1

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


#2

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:


#3

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


#4

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.


#5

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


#6

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


#7

Thanks Roy, any help would be appreciated.


#8

I am also interested in this, thanks in advance!


#9

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


#10

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.