Accessing Connection Count and 2D in Code

Hey!

I have a script to automatically build a series of GridGraphs for me and I’m having some issues figuring out how to access a few parameters that are available in the UI.

The first is “Use 2D” for the GridGraph, not the GraphCollision. If all this does is rotate the X Vector by 90, that’s fine, I can do that without a problem and am doing it now. If it does something else, the ability to access it would be great.

Secondly, and more important, I can’t seem to find an exposed variable or function that changes the default node connections from 8 to 4 for GridGraphs. If I’m just missing it, please let me know. If not, where is it set so that I can just go into the code and expose it and can you please expose it going forward?

Thanks!

EDIT: Nevermind on the second part. The Connections count is accessible as gg.neighbours = NumNeighbours.Four;

1 Like

Hey,

the use 2D Physics can be accessed as next:

GridGenerator.collision.use2D

Read moer about the GraphCollision here: https://www.arongranberg.com/astar/documentation/dev_4_3_11_59993326/graphcollision.html

I am asking about the 2D orientation of the map, not GraphCollision. Sorry for being unclear.

ah ye sorry my bad, I just opened a graph and looked for the first 2D thing I could find.

Ye it doesn’t do anything but rotate the graph.
here is the code:

bool new2D = EditorGUILayout.Toggle(new GUIContent("2D"), Is2D(graph));
			if (EditorGUI.EndChangeCheck()) {
				graph.rotation = new2D ? new Vector3(graph.rotation.y - 90, 270, 90) : new Vector3(0, graph.rotation.x + 90, 0);
			}

so you’ll want to set your graph as next:

graph.rotation = new Vector3(graph.rotation.y - 90, 270, 90);
2 Likes

Awesome, thanks! That covers everything.

Though I’ll still throw in a request for that 2D rotation to be exposed or documented somewhere, unless the specific rotation doesn’t matter much and the X+90 would work since most people will land on that pretty easily. Though it’s probably a fairly small use set even then.

1 Like

Hi

The particular 2D rotation does not matter that much, that particular rotation is just slightly nicer to work with sometimes when using other 2D stuff as the axes point in the expected directions.