Lag spike enabling behavior

hovgaardgames

New member
Hi, I am having a problem with my behavior tree, I get a huge lag spike every time is enabled, as you can see in this image:
1699451932703.png

It seems that the problem is in the deserialization of the tree, so I read in other posts that the solution is to pool and call the Init function of the external trees before actually calling to the EnableBehavior function. So, I made this to try it:
1699452053190.png

However, it is not working, all the heavy load is being carried by the EnableBehavior function. Seems like the Init function is doing nothing. The tree has multiples behavior references that have more behavior references inside. Is that the problem? And if that's the case, can I do something to solve it? Thank you.
 
Calling init on the external behavior tree will consume all of the behavior tree references so that wouldn't be the cause. After the behavior tree is enabled you can tick it once to have it load all of the tasks, but your spike is within the deserialization method so that likely won't help. It will ensure the tree is loaded though. For the best performance you should switch to binary serialization, and you could also have the tree load with async (set on the behavior tree component).
 
Well, switching to binary serialization made the lag spike bigger, and loading async seems that it's not an option because I'm mapping variables. So, what I tried is to call the EnableBehavior function once, disabling it right after, and then my tree is already deserialized, so the next time I call Enable behavior it doesn't have to deserialize it again.
 
Top