Running trees on different frequency to reduce spikes

PaoloAtRebelpug

New member
Hello there,

I need your help please.

We are trying to optimize the game so that it can run without issues on lower requirements.

roboplant-v0-3-12-game-pre-optimization.jpg
This is the scene we use for optimization, every room, structure and robot has a behavior tree for their tasks. The tick is manual on a routine and goes off every 0.1 seconds. We optimized every tree (beside for the workers) in a way that there are only few checks and are based on enum comparisons. For the worker we did the same when he is not working (Running) a specific task.

This below is the profiler for that scene when the game is standalone:
roboplant-v0-3-12-profiler-pre-optimization.jpg
As you can see there are spikes every time the tree goes off, so I am wondering if there is a way to split the trees in two groups, one for the workers and one for everything else with the objective to spread the load. What do you think? How could we achieve that?

Thanks and have a great day,
Paolo

EDIT: I managed to split the trees in two groups! If anybody want to know how to do it is about setting the tick to manual then calling tick(tree) on need
 
Last edited:
In our project we realized that the most processing power consuming task was the within distance. We tried to optimize the trees around it and then later we made an edit to the task with a "collision check interval" value, so that even within a single tree if the within distance task is not so important we give it a high value so sometimes it only checks the same thing every 1 second or if it's an important sequence requiring immediate reaction then we give it a low value like 0.1 sec
 
After several testing we realized that one big issue is the number of actions/conditions are called every frame, even for just checking boolean.

Example: 10 AI with each checking in 5 different branches a boolean (if status == ...), by grouping them in a single condition we improved the performance by a good amount.

For the distance checking we implemented our own checks :)
 
Thanks!

We ignored boolean checks so far I should pay some attention on that part as well I guess.

How many agents you have on the scene and what are the specs you are trying to optimize for?

We have up to 50 and they have 4-5 checks on every tick. When we reduce the distance checks, they run smoothly on a regular PC. We didn't try to optimize for mobile though.
 
We use the behavioral tree for every AI in the game (structures, workers, rooms) so we can have 100 trees, of which 50 will do 3-5 conditionals when idle and the rest 10-20 actions/conditions. Mine is a 4y old gaming pc and I could see the actual spikes dropping 5-10 fps. What are you using to check the fps?
 
You seem to have lots of agents around. I would like that extra responsiveness from all entities but we don't really need that I assume.
We use profiler and deep profiler to check the sources of extra ms for each frame. Similar to you I guess.
 
Yeah beside workers we use the behavioral tree on structures and rooms so that they can request by themself (build, repair, destroy) orders and more. But after discovering the impact of it I had to scale it down and group as much as possible
 
Top