Slow Update Rate in the Behavior Graph

Hello, dear Unity Developers!

I have a behavior tree with conditions and simple one-time actions (like Set Variable to Value):

I noticed that when an enemy is in Patrol state, and then it Dies in the game, the switch to the first branch happens not instantaneously. It takes several frames before the Try In Order switches to the Death branch.

I have read in the docs that Behavior Graph is designed to be performance efficient, but in my case this efficiency causes problems.
It’s strange to see in the game that the bullet has already hit the enemy, but the animation of the death played with delay.

Dear Unity Developers, could you please tell me:

  1. Why this happens? Is it intended?
  2. Is it possible to increase the Update Rate of the Tree?
  3. If not, what workaround would you suggest?

Platform: Windows 10
Behavior Version: 1.0.7
Unity Version: 6000.0.25f1

Thank you!

Hi,

We’re aware of this issue and are actively working on it. Fundamentally when it comes to a sequence like the Try In Order each child is executed in successive frames. We’re currently working on making the graph do as much as it can each frame rather than spreading it out like it does now.

Thanks for the report.

1 Like

@davidlovegrove , thank you for such a quick answer!

Could you please tell me:

  1. Do you have a workaround while your team is trying to solve it?
  2. Do you have an idea in which release the fix will come? Like, in the next, or maybe in the next 5 updates?

Thank you again!

Hey @unity_30D89FB79A72844A3914 ,

I’m working at it with the hope of getting it out next week, but if I miss the window it’ll be 3 weeks at most (unless some disaster strikes)!

As for a workaround, unfortunately I can’t offer an easy one that won’t bring up potential issues as a side effect…

You can try replacing your Sequence and Selector files with these updated ones, but it’s not a complete fix for all cases, though it should help.

SelectorComposite.cs (2.0 KB)
SequenceComposite.cs (2.1 KB)

@ShaneeNishry , thank you for the provided code!

I tested and it seems like Graph reacts much more quickly than before. Thank you for your work!

But I noticed one possible issue with the code you provided:
Let’s imagine that in the Selector (TryInOrder) we have 2 children that are both Failed. From your code, I see that for Selector it will be still a Success:

protected Status StartChildNodesUntilCompleteOrWaiting(int childIndex)
{
    m_CurrentChild = childIndex;
    while (true)
    {
        if (m_CurrentChild >= Children.Count)
        {
            // HERE WE'LL HAVE SUCCESS EVEN IF CHILDREN WERE FAILED
            return Status.Success;
        }

        var status = StartNode(Children[m_CurrentChild]);
        if (status == Status.Failure)
        {
            // Move on to the next child.
            ++m_CurrentChild;
            continue;
        }

        if (status == Status.Running)
        {
            return Status.Waiting;
        }

        return status;
    }
}

Now, imagine that this Selector is within another Selector. The outer Selector will not check for other children because the inner Selector always returns Success.

Could you please tell me, do you see this as an issue?

Thank you again!

Hey, you’re right! I’ll make sure I correct this for the release :slight_smile:

The correct way would be to just return failure there, as we would’ve returned success if a child succeeded so you should be able to safely change that

@ShaneeNishry , thank you very much for such a quick reply!

This:

if (m_CurrentChild >= Children.Count)
{
    return Status.Failure;
}

in the SelectorComposite.cs works well for me. I checked the same method for SequenceComposite.cs - the return of the Success seems correct there.

I am glad you guys directly work like that with the community. I respect that very much!

I’ll mark your reply with the attached scripts as a solution. I wish you a very good day and evening!
(and if possible, could you please ask someone to check my recent bug report - Changes made in Subgraphs are not perceived by the Main Graph - the bug is very annoying)

Thank you again!

You’re welcome! Working with the community is really important to me and the team and I’m glad it’s showing :slight_smile:

Thank you for communicating with us and helping us improve the package!

P.S. I replied on the other thread.

2 Likes