Pooling behaviours and performance

DirtyHippy

New member
Hi -

My npcs all share the same (large) external behaviour tree. My npcs are all pooled, so once the behaviour tree instance is setup, I don't really have any reason to return the behaviour tree itself to an internal pool (but I think behaviour designer does this automatically for you).

I've been doing some testing on spawning npcs (8) in a deep profile and reinitializing the trees is taking about half the time for the entire spawn, and also doing a ton of allocations. Is there any way to just reset the current in-memory tree rather than returning it to the pool? I'd like to more tightly control when the behaviour tree is returned to its internal pool.

1603990667130.png
 
So I reviewed those threads and I think I have figured out how it works under the hood. Honestly I found those threads a bit awkward. Most people are probably like me - they have pooled agents, those agents have a behaviour tree component with an external behaviour. They spawn/despawn the agent and don't mind some initial setup on the first spawn but ideally after that would like it to be minimal.

The above screenshot was after the pools had reached a steady state. Seeing the threads focus on "pausing" I poked around in the Behaviour Designer code and I think the key is that behaviour trees that are enabled/disabled without pausing are torn down and recreated. Behavour trees with "PauseWhenDisabled" or explicitly paused are not destroyed but simple removed from the update loop.

So simply setting the behaviour to pause when disabled - and then optionally restarting it with "BehaviorManager.instance.RestartBehavior" (FYI - this felt odd it was not a method on the behaviour tree itself) - you avoid the re-init and the allocations (verified in a deep profile).
 
Top