Hello Aron,
I was able to discover that when I use
p.nnConstraint.graphMask = 1 << 0;
it only works when the other graphs are first disabled and then re-enabled again (when I added the enabled[i] feature to the editor to test it out), so I figured that it had something to do with initialization. I created a way for the system to first disable all graphs and then re-enable them in .5 seconds for me automatically during startup, and it works now, so it MUST mean the graphs’ initializations have something to do with it.
In AstarPath.cs, I added a Start() function
public void Start() { for (int i = 0; i < enabled.Length; i++) { enabled[i] = false; } }
to first disable all the graphs at startup. Then, in Update(), I added the code…
if (switchOn && !switchOn2) { Scan(); switchOn2 = true; } if (Time.time > .5 && !switchOn) { for (int i = 0; i < enabled.Length; i++) { enabled[i] = true; } switchOn = true; }
and 2 variables in AstarPath.cs called switchOn and switchOn2, which are boolean. switchOn becomes true .5 seconds after the Start() function executes, which indicates that all the graphs are re-enabled .5 seconds after they were disabled by the Start() function, but if I use the function Scan() immediately afterwards in the same Update() sequence when all the graphs get re-enabled, I run into the same problem, so Scan() happens during the next update sequence, and so I use switchOn2 for that.
Then, I ran into a couple of other problems in AIFollow.cs because when there are no graphs enabled (at first), it can’t return a graphIndex to a null node, so in GetGrid(), here is what I’ve done…
`
public int GetGrid(Vector3 pos) {
if (AstarPath.active.GetNearest(pos).node != null) {
return AstarPath.active.GetNearest(pos).node.graphIndex;
} else {
return -1;
}
}
`
in OnValidGraph(), I also did…
public bool OnValidGraph(Vector3 pos) { if (AstarPath.active.GetNearest(pos).node != null) { return validGraph(AstarPath.active.GetNearest(pos).node.graphIndex); } else { return false; } }