Any way to run with more than one Astar component in a single scene?

So, I’m building a scene at the moment that generates multiple different maps drawn across separate planes - and then the Seekers try to solve them. Each map has a different set of seekers, with all maps being in competition with oneanother.

However, after building up the map logic, I found that spawning more than one instance of Astar caused the following error to appear;

You should NOT have more than one AstarPath component in the scene at any time.

Followed then by exceptions due to me breaking this rule.

Is there any possible way to actually get anything like this working - in having several different maps spawning/running seekers at the same time? Or is this a no go?


You cannot have more than on AstarPath component in each scene, however you can add multiple graphs to a single AstarPath component.

You can select which graphs a particular search will use by setting the ‘graphMask’ parameter of the Seeker.StartPath call.

I’m running into the same issue even though I have Astar objects in different scenes, but those scenes exist simultaneously, just for a brief second. That’s long enough for the whole system to be fouled up. It’s really disappointing, as it means I can’t have a fluid, large world divided into scenes, unless I have some weird artificial transitional scene that loads up between the two Astar scenes, making sure to unload one before loading the other.

Is there any way to not have this be based on a Singleton pattern? How much effort would that require? Assuming I do that in my own local version of the codebase, that would pretty much mean I can’t upgrade at that point.


There is no easy way to avoid the singleton pattern.
However one approach that could work for you is to save and load the graphs using code instead:
This way you could stream in your new scene, and when it has finished loading you load the new pathfinding graph.
Also. Wouldn’t it be possible for you to just have a single pathfinding graph that covers your whole world. Just because you don’t have the geometry loaded somewhere doesn’t mean you cannot have a pathfinding graph there.