Task being stopped and restarted every frame leading to NavMesh stuttering

Chazzmundo

New member
Hi, I have an issue where all of the NavMeshMovement based tasks (both existing and my own custom ones) are being restarted in the BT each frame which is causing the AI agents to stop moving, recalculate the NavMesh path and thus causing both performance issues as well as the AI agent to do "micro-stuttering" where it can only move a tiny amount each time due to the path being reset.

There's a hacky somewhat workaround to this by setting the AI agent acceleration to very high but I don't understand why

Here you can see the task being stopped (which therefore stops the agent and will restart the next frame)1748564028644.png

The callstack triggering this removal being here (this is the part I can't work out what's going on and given it's compiled, I can't debug too much info out of it):
1748564100596.png


After this is stopped, the task will be started once again the very next frame and this issue will repeat.
Note that in this route, I'm returning `TaskStatus.Running` each frame so it's not due to what I'm sending back.


My BT looks like this:
1748564274592.png
The `Pursue Dynamic Target` is a custom task my end inheriting from `NavMeshMovement` but this also happens the exact same for inbuilt tasks like `Wander` (exists outside of the visible frame of this screenshot but has the same problem).

I've tried removing/changing the Abort Type all the way up the chain to the root thinking that may be the cause (I still don't get fully how this works to be honest and am sure I'm misusing this but it doesn't seem to properly re-evaluate anything without setting to it to `both` on pretty much everything).

One thing that may be relevant is that I do dynamically generate the NavMesh at runtime from time to time as the player moves around the world (it's an endless procedurally created 2D game). However, that's only happening once every few seconds at most based on how far the player moves from the last build point whereas this micro-stuttering caused by restarting the BT NavMeshMovement Tasks is happening much more commonly than that.

Any tips you can provide on how to prevent the tasks being cancelled and restarted each frame would be greatly appreciated!
 
The NavMeshAgent is being stopped because the task is ending, likely through an abort or the Utility Selector switching branches. If you don't want the NavMeshAgent to be stopped then you'll need to redesign your tree a bit. If you've removed all of the conditional aborts then it's likely due to the Utility Selector.
 
Thanks Justin, that's good info.

How can I redesign it in such a way that I can stop the BT from killing & restarting the child nodes (especially when they're not changing to another child as a result) while still keeping the utility evaluation behaviour?

For context, my CanUseAttackConditional generates a dynamic scoring based on a component on the owning agent so it can be different between frames but my understanding is that this shouldn't be re-evaluated while the current active task is still running?
 
I don't believe there's an option in version 1. In version 2 I added an option to the Utility Selector to not switch if a branch is running. For version 1 you'll need to create a new task that is similar to the Utility Selector and does not break when a child is running.
 
Got it, thanks for the fast response!

I'm debating whether it's worth the upgrade mid-project or to just write my own. Is there a handy sheet showing some/most of the smaller changes like this when comparing the 2?
 
We have a high level overview here but there are way too many minor changes like this to list 🙂 It was a complete rewrite taking into account the decade of experience in order to make a huge number of improvements. If you have a specific question on version 2 I can definitely answer it.
 
Understood, thanks!

I guess the main question then would be what are the difficulties/time-consuming parts of upgrading?
My understanding is that I'd need to recreate all the BTs themselves from scratch (e.g. from screenshots I take of my old one) as there's no upgrade functionality tool provided?

I only have a few custom actions myself so I'm not too worried about upgrading them but I do have ~8 BTs with 20~30 nodes in each.

Additionally, I had to make some small changes to some of the provided tasks (e.g. NavMeshMovement was calling stop on NavMeshAgents that weren't on the NavMesh for example which was spamming errors). Not sure yet if these would need to be replicated in the new version.

One other question I have is about the 2D support. The version I'm using was quite limited and often things weren't working with an XY oriented 2D setup without some small changes. How is the 2D support for this version in comparison?
 
I guess the main question then would be what are the difficulties/time-consuming parts of upgrading?
My understanding is that I'd need to recreate all the BTs themselves from scratch (e.g. from screenshots I take of my old one) as there's no upgrade functionality tool provided?

I only have a few custom actions myself so I'm not too worried about upgrading them but I do have ~8 BTs with 20~30 nodes in each.
Recreating the tree is going to be the most time consuming. With that said, 30 nodes each tree won't be that bad especially since you don't have many custom takes. You are correct in that there is not any migration tools.


Additionally, I had to make some small changes to some of the provided tasks (e.g. NavMeshMovement was calling stop on NavMeshAgents that weren't on the NavMesh for example which was spamming errors). Not sure yet if these would need to be replicated in the new version.
There have been a ton of improvements to the add-ons so chances are you won't need to make any changes. If you do they would be similar to what you did before. Though in the case of the navmesh error I am interested in learning why you are starting a navmesh task when it's not on the navmesh.
One other question I have is about the 2D support. The version I'm using was quite limited and often things weren't working with an XY oriented 2D setup without some small changes. How is the 2D support for this version in comparison?
Fully supported. This is related to the add-ons, but I am now testing with 2D as well so that aspect works much better.
 
Though in the case of the navmesh error I am interested in learning why you are starting a navmesh task when it's not on the navmesh
I have some bugs I'm still fixing with dynamic NavMesh generation and enemies sometimes spawn off NavMesh (or it disappears very briefly under their feet). That seems to trigger a re-evaluation of the BT and the inbuilt Navmesh tasks are not checking if on NavMesh in their CanStart conditions so were exiting after the 1st update, calling Stop() and causing that error.

Good to know that you're testing directly in 2D! Sounds absolutely worth the upgrade then. Thanks for all the help and info here!
 
@Justin I'm in the process of upgrading to Pro (version 2.0.11 for Unity 6000.0.47f1) and I've noticed several issues:
  1. There's no inbuilt replacement for the `WithinDistance` Conditional (I own and have imported the `Movement Pack for Behavior Designer Pro`)
    • I've replicated my own for now but strange that such a common Task isn't existing in the Pro upgrade?
  2. Performance is severly reduced with having the Pro Editor window open
    • I went from ~40fps in my runtime with the older one open to ~12fps with the new one (that has substantially fewer nodes as well as I haven't finished replicated them
    • I don't really have a workaround for this & haven't profiled it yet but I can say that I do still have the older version installed too (while I migrate BTs and custom Tasks) and there's a very clear difference
    • Sometimes dragging Tasks around in the Pro Editor causing Unity to freeze for several seconds
  3. I can't edit the BT at runtime (e.g. disabling the nodes, reordering the positions to have it run in a order based on structural priority)
    • This was a major help when developing the old version as I didn't need to restart the whole game to test each possible BT change which saved a huge amount of iteration time
  4. It's annoyingly slow (UX wise) to find the Task I'm looking for when adding a new Node. For example, typing "Sequence" which is one of the most commonly used Nodes for my AI) is hidden after many other options that contain that word. Meaning I need to scroll, locate and click to re-add this each time (or find and duplicate an existing one)
    • Can you prioritise the inbuilt actions from the plugin itself over anything in the project it may dynamically pull?
  5. (Important blocker): The BoolComparison doesn't correctly pull the correct value. In the below pic, you can see I have a SharedVariable<bool> (referencing the new opsive namespace so not the old `BehaviorDesigner.Runtime` version) which should be True but the SharedVariable in the BoolComparison 1749887931051.png
    1749888084925.png
    (the CanFlee is set to true in the code and it shows correctly that the value of that variable is still true after setting it in the tree)
    1749888223147.png
I've only spent about 3hrs on it so far so it's still early but these are the problems that I'm facing straight away.

#5 is the biggest problem by far and is a complete blocker for me being able to use this plugin. Any idea on what might be going wrong in this setup?

I've limited this new BT to a very simple setup just as a proof of concept for the migration. Once I can prove this small part works as expected, I'll move forward with migrating the wider BT
 
Thanks for your upgrade!

There's no inbuilt replacement for the `WithinDistance` Conditional (I own and have imported the `Movement Pack for Behavior Designer Pro`)
  • I've replicated my own for now but strange that such a common Task isn't existing in the Pro upgrade?
That's included with the Senses Pack now.

Performance is severly reduced with having the Pro Editor window open
If you can profile it that would be great. UIElements are now used instead of IMGUI so it should be quicker.

I can't edit the BT at runtime (e.g. disabling the nodes, reordering the positions to have it run in a order based on structural priority)
This is expected due to the structure being baked beforehand. In version 1 reordering wouldn't persist at runtime either, though you could disable.

It's annoyingly slow (UX wise) to find the Task I'm looking for when adding a new Node. For example, typing "Sequence" which is one of the most commonly used Nodes for my AI) is hidden after many other options that contain that word. Meaning I need to scroll, locate and click to re-add this each time (or find and duplicate an existing one)
This is know, and a new filter window will be coming in 2.1:


(Important blocker): The BoolComparison doesn't correctly pull the correct value. In the below pic, you can see I have a SharedVariable<bool> (referencing the new opsive namespace so not the old `BehaviorDesigner.Runtime` version) which should be True but the SharedVariable in the BoolComparison
Are you able to send a repro of that? Are you using subtrees?
 
Back
Top