Noticing frame rate drops when there are multiple nested 'BehaviorManager.RunTask()' calls

iozsaygi

New member
Hey, I am noticing constant frame rate drops and when I profile the game I notice there are stacked calls of BehaviorManager.RunTask() API.
The behavior manager instance is set to Run Every Frame.

The game is turn based so I also tried to manually update behavior trees that I am going to enable but no luck with it. They are just not getting activated.
Here's how I am trying to enable behavior trees so far.

Code:
internal async Task StartProcessingBehaviourTreesWithOrderAsync()
{
            Warmup();

            while (behaviourTreeActivationQueue.Count > 0)
            {
                taskCompletionSource = new TaskCompletionSource<bool>();

                var behaviourTree = behaviourTreeActivationQueue.Dequeue();

                var networkedUnitController = behaviourTree.GetComponent<NetworkedUnitController>();
                Debug.Assert(networkedUnitController != null);

                // Only iterate on AI if it is not stunned or slept.
                if (!networkedUnitController.IsAbleToPerformAnyAction()) continue;

                behaviourTree.EnableBehavior();

                // I tried 'behaviorManager.instance.Tick(behaviorTree);' here but no luck.

                ELAPI.Log(
                    $"Enabled behaviour tree, there are {behaviourTreeActivationQueue.Count} behaviour trees left to activate.",
                    nameof(AIBehaviourTreeActivator));

                await WaitForBehaviourTreeSkipSignal(behaviourTree);
            }
}

I am coming into a result that these stacked calls ending up with the frame rate drops so I would be really happy if I can learn to workaround this. For a turn based game it should be enough for me to tick and enable behavior once.

1733830983652.png

Thanks!
 
It looks like CampaignTakeCover.OnUpdate is taking most of the time. It also generates a lot of allocations. The behavior tree traversal looks quick, so it's up to optimizing that task.
 
It looks like CampaignTakeCover.OnUpdate is taking most of the time. It also generates a lot of allocations. The behavior tree traversal looks quick, so it's up to optimizing that task.
Hey Justin.

Yup, I was able to resolve this by further optimizing gameplay code and some string allocations.

Thank you for the response.
 
Back
Top