Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Behaviour Tree Sequence Node

Discussion in 'Scripting' started by Terraya, Sep 28, 2020.

  1. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    Hey there!

    First of all,
    isnt the "goal" of a "sequence" in a behaviour tree to iterate one Node after another and in case
    one node is Failure, the sequence returns false, in case success , the next node gets taken?

    i´ve found a few sequence codes and also made one myself but all of them iterate through
    all of the childs even one is running ...

    i dont realy understand, here is the code:
    Code (CSharp):
    1.     public override NodeState Evaluate()
    2.     {
    3.         bool anyChildRunning = false;
    4.  
    5.         foreach (Node node in m_nodes)
    6.         {
    7.             switch (node.Evaluate())
    8.             {
    9.                 case NodeState.RUNNING:
    10.                     anyChildRunning = true;
    11.                     break;
    12.                 case NodeState.SUCCESS:
    13.                     break;
    14.                 case NodeState.FAILURE:
    15.                     _nodeState = NodeState.FAILURE;
    16.                     return _nodeState;
    17.                 default:
    18.                     break;
    19.             }
    20.         }
    21.         _nodeState = anyChildRunning ? NodeState.RUNNING : NodeState.SUCCESS;
    22.         return _nodeState;
    23.     }
    i mean "foreach" is going through one after another and in case one is running, it waits until its successfull or failure, the problem here is, i made a test Node which returns "RUNNING" and "SUCCESS", i put the RUNNING node as first and the "SUCCESS" node 2nd, but its iterating through both ... i mean, it doesnt wait until running returns success of failure to go to the next one...

    anyone any idea? :/