I have a few different objects that can move on different surfaces in my scene. These objects are instantiated in runtime, and I make a new GridGraph for them that follows the object when they get instantiated. Code:
AstarData data = AstarPath.active.data;
GridGraph gg = data.AddGraph(typeof(GridGraph)) as GridGraph;
gg.name = name + data.graphs.Length + "_Graph";
gg.SetDimensions(50, 50, 0.05f);
GetComponent<ProceduralGridMover>().target = transform;
data.graphs[data.graphs.Length - 1].Scan();
I then want to make sure they only stay on their own graph, by saying
GetComponent<Seeker>().graphMask = GraphMask.FromGraphName(gg.name);
And this kinda works. The first time i instantiate an object, it the seeker.graphMask
is set to whatever it was last time. Then the next time I instantiate an object, the new object’s seeker.graphMask
is set to the previous object of that type’s seeker.graphMask
. In other words, it goes to the previous instance of the object.
If I instantiate a different object, it starts again with whatever it was last time. Then the next instance of the same object gets the previous instance’s seeker.graphMask
, etc.
What is the correct way to do this?