Adding Switch Condition

In addition to self-state switching, a conditional mechanism is necessary for switching to the Listen and Speak states to respond to user interactions.

  1. Idle state switches the Listen state when a user starts typing.
  2. Listen state switches to the Speak state when the user sends the text.

Follow the instruction below to add the two switch conditions in the Behavior Tree.

  1. In the Behavior Tree graph, right-click on the empty area and select Composite > Priority Pick.
  2. A Priority Pick node is created.
  3. To add a trigger condition of clicking the Send button from the Chat window, create a Check Speech Request node by right-clicking on the empty area and selecting Decorator > Speech > Check Speech Request.
  4. To add a trigger condition of keyboard typing from the text field of the Chat window, create a Check Speech Input node by right-clicking on the empty area and selecting Decorator > Speech > Check Speech Input.
  5. Select the Check Speech Input node, and set a Trigger Cooldown period in the Parameters section to prevent the duplicate execution.
  6. Connect the two conditional nodes to the Priority Pick node.

    * Under the Priority Pick node, the left one has a higher priority than the right one (when both nodes are executable).
  7. Create a Switch State node for each conditional node, and select a proper state in the Parameters section to complete the state switching.
    • When a user starts typing, switches to the Listen state.
    • When a user sends out text, switches to the Speak state.

  8. Use a Comment node to place these nodes in a group, renamed as Conditional Mechanism.
  9. Configure the Speak state to generate a speech animation to chat with users.