Non-MonoBehaviour modifiers

Hi,
You can do AstarPath.StartPath from a script, which is very handy in my case since i have a navigation handler class that my game asks for paths, so that i can abstract/wrap the A* implementation behind a handler.

However, is there no way to use something like a modifier resolver without having to attach modifiers to game objects? The seeker implementation expects all modifiers to be attached to the same gameobject. It would be extremely handy if i could get the final path of a AstarPath.StartPath while passing in a list of modifiers that i want applied.

Hi

You can configure a single GameObject with a Seeker and then call seeker.PostProcess with the path that you want to apply modifiers to.

Thanks, that worked well and turned out a simpler approach than my previous setup.
I guess it will work with many simultaneous calls in parallel for each enemy since its run in different threads?

Hi

What runs in different threads?

Modifiers are generally not run in separate threads because a lot of them use the Unity API such as the Physics API and that is not thread safe. Some modifiers, like the SimpleSmoothModifier, should be able to run in a separate thread if necessary.

I mean, if i have a second call to StartPath on the seeker before the first one has fully completed, then that wont interrupt any calculations of the first call?

Yes it will. For the Seeker. Seekers are primarily intended for a single unit and since a single unit always follows a single path, it makes no sense to calculate two different paths at once. So if a new path is requested while another one was being calculated, the previous one will be aborted. Use AstarPath.StartPath if you want to interleave path requests.

Perfect, oh and thanks for the recent library update, im trying it out at the moment :slight_smile:

Note the updated reply. I misread your post at first.

Hmm ok, have to do some adjustments then.

I thought you were already using AstarPath.StartPath?

What I am suggesting is that you do something like this

void Start () {
    // Start a bunch of paths
    for (int i = 0; i < 100; i++) AstarPath.StartPath(start, end, OnPathComplete);
}

void OnPathComplete (Path path) {
    seeker.PostProcess(path);
    // Do other stuff
}

Yes, correct. I was but had issues with it so i tried a new approach. This is what i had:

		var path = ABPath.Construct(start, end);
		path.nnConstraint.graphMask = Globals.Navigation.NavigationMeshGraphMask;
		path.callback += startPathResult =>
		{
			seeker.postProcessPath += postProcessResult =>
			{
				var result = new NavigationPath();
				result.Nodes.AddRange(postProcessResult.vectorPath);
				completed(result);
			};
			seeker.PostProcess(startPathResult);
		};

		AstarPath.StartPath(path);

However, it results in a NullReferenceException in Seeker.cs line 190 (preProcessPath§). Any ideas?
The Seeker GameObject contains a single modifier, the Funnel and both the Seeker and Funnel have default settings.

Oh and NavigationMeshGraphMask = 1 << 0

Ah, it seems you have stumbled upon a bug. It tries to run the preProcessPath delegate when it should have run postProcessPath. I have fixed that in my dev version now and the fix will be included in the next version.
That was a really old bug. That code has not been changed in ages, but nothing in the internal scripts uses it and I haven’t had any reports about it from users.

However you do not have to use the postProcessPath delegate. The PostProcess call is synchronous, so you can simply skip that delegate.

Alright, good to know i wasnt doing anything wrong there. If its a small fix in the Seeker script, perhaps you could send it to me at johan.gl.hansson at gmail.com? Otherwise, i will wait for the next version.

Hi

Just uploaded 3.8.1.
However you will not really need that update since you can just skip using that delegate and all will be fine.

1 Like