Proper way to stop / speed up tree ticking?

caleidon

Member
In my game, the player has the ability to pause the game or increase the speed to 2X, 4X etc...

I'm unsure what the correct way is to control the speed (ticking) of the behavior trees.

Where's what I think is the correct way:

1. Add a GameObject to the scene, call it "Behavior Manager".
2. Add the "Behavior Manager" component to that GameObject.
3. Set the Update Interval to Manual.
4. Inside of my time management script, update the tree on every custom tick (every 0.2 seconds) by calling "BehaviorManager.instance.Tick();", which will now update all of the trees.

Now, I should be able to pause the game or increase the speed, which will change the rate of my custom ticking, which will in turn slow down or speed up the behavior trees, correct?

PS: The reason I don't set the Update Interval to Every Frame is because I'm using a special modifier instead of directly changing Time.timeScale.
 
If you don't change Time.timeScale then you should manual tick the trees. If you however are changing the timeScale then the behavior tree will automatically be ticket with that new rate since it affects when Update is called.
 
If you don't change Time.timeScale then you should manual tick the trees. If you however are changing the timeScale then the behavior tree will automatically be ticket with that new rate since it affects when Update is called.
What do you recommend as the optimal tick rate? When the trees are ticked, all tasks and their TaskStatuses are evaluated, correct? That means it's crucial to tick the trees every frame, and not any less often?
 
When the trees are ticked, all tasks and their TaskStatuses are evaluated, correct?
Yes.

That means it's crucial to tick the trees every frame, and not any less often?
Not necessarily. It all depends on your budget for AI processing that you can afford. As an extreme case a turn-based game will only need to tick once every time it is the AIs turn. Even for faster paced games you can likely slow the speed at which the tree ticks. But it is completely dependent on your project so you should experiment with it.
 
If you don't change Time.timeScale then you should manual tick the trees. If you however are changing the timeScale then the behavior tree will automatically be ticket with that new rate since it affects when Update is called.
Hello there,

a question please.

When the player load a game I set the timescale to 0 then I load all the data and the set it to 1 again. But I am having an issue with our tree. The OnUpdate of an action get triggered even though the timescale is at 0 messing up with the loading process. The Behavior Manager is auto instantiated so I use the default settings. Do you have a way to prevent it from updating during that time please?

I considered two workarounds:
- Disable all the loaded content and enable it at the same time --> I am worried about the performance here doing so
- Manually override during the loading process the tick frequency --> This seems the most plausible in case I can't get it to work automatically

Thanks,
Paolo
 
OnUpdate will be called on the first frame because the tree is automatically ticked once it has loaded. If you don't want this behavior you'll need to modify the BehaviorManager (runtime source is available on the downloads page).
 
Top