How to ensure there is ALWAYS a task running?

caleidon

Member
I am working on a custom saving system and I managed to find a way to get the currently running node with some dark voodoo magic.

C#:
Task runningNode = Owner.GetActiveTasks().Find(task => ((GrimAction) task).GrimNodeID == RunningNodeID);

I keep the RunningNodeID updated when some task starts in OnStart() and then I try to find that task in all of the running tasks. However, I've noticed that sometimes runningNode throws a NullReferenceException. Upon looking deeper into the problem, I've noticed that it is possible for a tree to complete a task and not immediately go to the next task, but instead hang around with no tasks running until (what I'm guessing) is the next BehaviorManager.Tick call.

Here's what this looks like:

Screenshot_1.png

There is no green node indicating that one is running, instead they're all just marked as completed.

However, I tick the tree pretty rarely, 5 times per second precisely. When I increased the tick rate to about 60 times per second, I noticed that I could no longer spam the saving function fast enough for the error to occur, aka, it seems like due to the massively increased tick rate there was basically always a task running. However, this problem still theoretically has a chance of happening.

My question - is there any way to make sure another task gets started immediately when the previous one finishes so that it is ensured that one task is active at all times so that I can save at ANY moment? I know I can always increase the tick rate (it is said that trees are extremely performant, so going from 5 to 60 ticks per second might not degrade performance at all), but I'd like to avoid it if possible.

Thank you!
 
Last edited:
If you have a limited tick rate then the number of active tasks will be based on that tick rate. With that said, at the root you could have a parallel task with an idle beneath it so the idle is always active.
 
Top