Setting the Seeker's graph mask in runtime

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 =;
GridGraph gg = data.AddGraph(typeof(GridGraph)) as GridGraph; = 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(;

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?


Could you show me the code you use to instantiate the objects and set the graph mask. The graph mask is a struct, so it is not possible for it to reference another object’s graph mask, you must have the wrong Seeker reference.

Thanks a lot for the rapid response.

First I instantiate a prefab like any other:

Instantiate(objectToSpawn, spawnPoint + positionOffset, Quaternion.Euler(spawnRot.eulerAngles + rotationOffset), objectParent);

Then I call a method that contains the code from the OP from a script called PlaceableVehicle:



objectToSpawn is still the prefab, you need to grab the reference to the thing you just instantiated:

var instantiatedObject = Instantiate(objectToSpawn, spawnPoint + positionOffset, Quaternion.Euler(spawnRot.eulerAngles + rotationOffset), objectParent) as GameObject;
1 Like

Oh wow I can’t believe I missed that… It’s been a long day at work (13 hours and counting :sweat_smile:).
Thanks a bunch Aron!

1 Like