Hello. I have to mention, I did check the procedural example (with the spider and perlin noise), but still don’t know how.
Ok, this is what I want to do. I have some platforms with flat ground and I just want to place GridGraph on each of those platforms with code (why do it with hand, if code is 100x faster, right?), scan and that is.
I know how to set propreties, but I don’t know how to properly Create Graph.
This code runs in ‘Editor’ extended class…, platform is MonoBehavior.
`
public void GenerateGraph(AstarPath astarPath, Platform platform) {
// previous graph
if (platform.graph != null)
astarPath.astarData.RemoveGraph(platform.graph);
//creating graph
var gridGraph = new GridGraph();
astarPath.astarData.AddGraph(gridGraph);
var platformGround = platform.platformGround;
// this is mesh collider on which NPCs will walk
var collider = platformGround.GetComponent<MeshCollider>();
// and I want the graph to be this wide
var bounds = collider.bounds;
var max = bounds.max;
var min = bounds.min;
var center = bounds.center;
gridGraph.center = new Vector3(
center.x,
max.y+1,
center.z);
var nodeSize = 0.5f;
gridGraph.nodeSize = nodeSize;
//calculating resolution
var countX = bounds.size.x / nodeSize;
var countY = bounds.size.y / nodeSize;
gridGraph.width = (int)countX;
gridGraph.depth = (int)countY;
gridGraph.ScanInternal();
platform.graph = gridGraph;
}`
It doesn’t actually. It messes up with AstarPath class, and I get bunch of NullReferenceErrors from it.
I don’t know how to insert and remove graphs properly from AstarPath class.
Also I know this was kind of quickly written post, if you do not understand it clearly just state so, I am in kind of rush and maybe missed details or two… Thanks!!
The number of graphs is limited to 255 mostly for memory reasons. The graph indices are stored for each node in a bitpacked field such that it only uses 8 bits of memory instead of e.g 32 bits for an int.
In the majority of cases people only use a single graph, and it is extremely rare to use more than 10.
Why do you need that many graphs?
It is possible to work around this though and create as many graphs as you want, it just requires you to change a few constants in the code (I can show you which ones if you need to do it).
My world (on server) contains 475 rooms in 7 levels, in every room there are obstacles. if i create grid for lvl, then many nodes not used. I think it’s worth removing the restriction, if there are no other suggestions.