How to avoid nested AddToTaskList on enable?

teofilo

New member
Hi,

Every time a gameobject with a behavior tree is activated in my game, a bunch of nested AddToTaskList happens (check image).
Extra info:
- Both Prefab and external behavior are pooled, so it's not a deserialization issue.
- If I disable/enable the gameobject on editor while playing, this doesn't happen.

Any thoughts?

Thanks!

AddToTaskList.png
 
My guess is that you have a tree with lots of children? This is related to initialization of the data oriented design. There isn't a way to completely avoid it but spawning multiple trees during a loading screen and enabling/disabling them at runtime will prevent it from slowing down your game.
 
spawning multiple trees during a loading screen and enabling/disabling them at runtime will prevent it from slowing down your game.
Trees are usually attached to prefabs, do you recommend instantiating the prefabs to fill in the pool during load time to achieve what you're talking about?
Also isn't init done on a separate thread when asynchronous load is toggled on which shouldn't show up in this profiler (main thread)
 
Trees are usually attached to prefabs, do you recommend instantiating the prefabs to fill in the pool during load time to achieve what you're talking about?
This post gives a good example of the workflow: https://opsive.com/forum/index.php?...es-produces-a-lot-of-garbage.3106/#post-18299

Also isn't init done on a separate thread when asynchronous load is toggled on which shouldn't show up in this profiler (main thread)
Yes, it is.
 
The benefit is that all of the objects have been initialized so you don't need to spend the time to reinitialize the objects when the tree is started.
 
Top