page_title: Behavior tree (artificial intelligence, robotics and control)
section_title: Sequence node
hierarchical_section_title: Behavior tree (artificial intelligence, robotics and control) / Key concepts / Control flow node / Sequence node
caption_attribution_description: English: Graphical representation of a fallback composition used in behavior tree.
context_page_description: A behavior tree is a mathematical model of plan execution used in computer science, robotics, control systems and video games. They describe switchings between a finite set of tasks in a modular fashion. Their strength comes from their ability to create very complex tasks composed of simple tasks, without worrying how the simple tasks are implemented. Behavior trees present some similarities to hierarchical state machines with the key difference that the main building block of a behavior is a task rather than a state. Its ease of human understanding make behavior trees less error prone and very popular in the game developer community. Behavior trees have been shown to generalize several other control architectures. Mathematically, they are directed acyclic graphs.
context_section_description: Sequence nodes are used to find and execute the first child that has not yet succeeded. A sequence node will return immediately with a status code of failure or running when one of its children returns failure or running (see Figure II and the pseudocode below). The children are ticked in order, from left to right.
  In pseudocode, the algorithm for a sequence composition is:
  1 for i from 1 to n do
  2     childstatus ← Tick(child(i))
  3     if childstatus = running
  4        return running
  5     else if childstatus = failure
  6        return failure
  7 end
  8 return success
caption: Figure II. Graphical representation of a sequence composition of N tasks.
exif: {}