I use very dynamic path finding, and up until 4.3.83 was able to have agents change their destinations aggressively using a movement script that called Seeker.StartPath. I’d pass a newly constructed ABPath into Seeker.StartPath, and then when I needed to immediately reorient the agent to the new path would call AIPath.SearchPath. This worked great until 4.3.83, when agent movement behavior that instantly changed paths without any noticeable pause, broke.
So after upgrading to 4.3.83 (Pro) I tried switching over to AIPath.SetPath per the Changelog, including moving my OnPathDelegate callback from Seeker.pathCallback to the newly constructed ABPath that gets passed to AIPath.SetPath. Unfortunately my agents now either pause, initially waiting for the new path to be calculated (this is expected behavior), or they appear to lose their OnPathDelegate callback after I call AIPath.SearchPath. I took a quick look at AIPath.SearchPath, and it calls ABPath.Construct, but passes in a null OnPathDelegate callback, which explains it being dropped after the call to AIPath.SearchPath.
My question is, what would be the best way to get back to that very dynamic path switching behavior I previously had using Seeker.StartPath and AIPath.SearchPath? And maybe this isn’t the right approach based on the previous question, but would it be possible to create an overload for AIPath.SearchPath that accepted an OnPathDelegate callback parameter? Along the same lines, is there a method that could simply accept a path and calculate it immediately instead of waiting a few frames? Thanks.
Generally, if you have a fast moving target. Just setting the destination property and using the Dynamic path recalculation mode should be enough. It might be a frame or so slower than what you could do yourself, but that’s rarely noticeable.
If you use ai.SetPath, I’d recommend polling ai.pathPending instead of using a callback. It’s true that the movement script will replace your own path callback if you pass the path to ai.SetPath.
To give more specific advice, I’d need to see the code you are using.
My AIPath component is set to use Dynamic path recalculation, but the problem was that when the agent was thrust into a room it would start up its pathfinding after it arrived at a ready position. Prior to 4.3.83 I could simply call Seeker.StartPath and then Seeker.SearchPath to wake the Seeker up immediately upon arrival at the ready position and it would instantly start path traversal (and agent movement). This is important because visually, if the room is in the camera’s viewport then the player will notice a significant pause of movement after the agent arrives at its ready position. In testing this morning it looks like the following code addresses that issue:
So thanks, I think ABPath.BlockUntilCalculated fixes that issue, and supersedes the functionality of Seeker.SearchPath.
What I’m still not getting is how to migrate from using an OnPathDelegate callback that I would assign to Seeker.pathCallback. My OnPathDelegate callback would previously handle evaluating running state of the agent when the path completes, for example is the agent active, did it reach its destination (using AIPath.reachedDestination), does it need to switch pathing goals, was there an error with the path (Path.error), etc. After 4.3.83 the OnPathDelegate that can be set as an ABPath callback during ABPath.Construct isn’t performing the same functionality since the callback gets dropped eventually, probably after the first path completion, or cancellation.
So moving forward what functionality mirrors the persistent behavior of assigning that callback to the Seeker, and having the callback fire when the agent completes a path (or has a path cancelled)? Ideally I’d like to avoid polling as having to evaluate state every frame via Update or by using a Coroutine or Async function, is less efficient than just having the callback wake up when the path is complete (I have many agents that are all frequently updating their movement goals, and thus paths). I’m guessing you’ll suggest polling on the state of AIPath.reachedDestination, which is fine, but is there any other way to migrate to the previous persistent “wake up when path completed” functionality provided by Seeker.pathCallback? Thanks for your feedback.