How Can We Help?

Behavior tree

You are here:
< All Topics

Introduction to behavior trees

Definition

A Behavior Tree is a decision-making structure used to control the behavior of virtual characters or systems. It consists of multiple nodes, each representing a behavior or decision step. Behavior Trees decompose complex behaviors into simpler, manageable sub-behaviors through a hierarchical approach.

In FactVerse Designer, Behavior Trees can be utilized to manage digital twin behaviors (such as starting and stopping equipment) and to handle state transitions (like switching an AGV from “standby” to “working” mode), among other applications.

Execution rules

1. The execution order of a Behavior Tree is from top to bottom and from left to right.

2. When the Behavior Tree reaches a terminal state, it will return to the root node and start executing again.

3. The root node can only have one child node.

4. When a node has child nodes, it executes its child nodes first, from left to right. After all the child nodes have been executed, it moves on to the next node.

5. The behavior tree runs in a continuous loop according to the specified sequence unless it is in idle mode or has been deleted.

Node type

Root node

When creating a behavior tree, a root node is automatically generated, serving as the starting point for the execution of the behavior tree. The root node cannot be deleted and can only connect to one child node.

Composite Nodes

Composite nodes control the execution order and logical evaluation of their child nodes. They include parallel nodes, selector nodes, and sequence nodes. Composite nodes can have multiple child nodes, which can be either composite nodes or action nodes.

    • Parallel Node: All nodes under a parallel node execute simultaneously. The success criteria for parallel nodes can be set to:
      • Success if any one child node succeeds
      • Success only if all child nodes succeed
    • Selector Node: The child nodes under a selector node execute in left-to-right order. As soon as one child node returns success, the entire selector node returns success and the subsequent child nodes are not executed. If all child nodes fail, the selector node returns failure.
    • Sequence Node: The child nodes under a sequence node execute in left-to-right order. Sequence nodes offer two traversal strategies.
      • Return failure if any child node fails
      • Return failure only if all child nodes fail

Action nodes

Action Nodes represent specific behaviors or tasks of the digital twin, such as moving along a path or waiting. Action Nodes are the leaf nodes of the behavior tree, where complex logic can be implemented. When an action node is executed, it performs a specific action and returns one of the following three return values:

    • Success: It indicates that the node has been executed successfully.
    • Running: It indicates that the node is still running, and it will continue to run when the behavior tree is called again.
    • Failure: It indicates that the node has failed to execute.

Node configuration

Node operations

1. Add nodes: Drag and drop nodes from the Node Menu into the Editing area.

2. Delete nodes: Select the node to be deleted in the Editing area and click the delete button on the toolbar.

3. Rename nodes: Select the node to be renamed in the Editing area and enter the new name in the node name area above the Attribute Pane.

4. Connect nodes: To connect Node A with Node B, drag a yellow connection line from the bottom of Node A and connect it to the top of Node B. Release the mouse to complete the connection.

5. Delete node connections: Hold down the right mouse button and drag over the connection line you want to delete to cut off the link between the two nodes.

6. Organize nodes: Select the Root Node and press the “L” key to automatically organize the tree’s format.

Common configuration of nodes

In behavior trees, node conditions and attribute settings often require obtaining the attributes of digital twins, locating digital twins, and retrieving the positions of digital twins.

Get attributes

Methods to get attributes

      • Select attribute directly: Choose the required attribute directly from the digital twin template.
      • Find attribute by ID: Retrieve attributes by searching with the attribute ID.

Get position

      • Manual entry: Users manually input the attribute value or ID directly.
      • Attribute of digital twin: Select to retrieve attribute values from specific attributes within the digital twin template.
      • Behavior tree attributes: Obtain attribute values from the attributes of the current behavior tree.
      • Current attribute: During the traversal of attributes within a container in the behavior tree, the attribute being traversed is the current attribute.

Way of finding digital twins

Basic method to find digital twins

      • Self: Choose the digital twin that is currently executing the behavior tree.
      • Temporary digital twin: Select a digital twin that is temporarily created or used during execution.
      • Digital twin in the attribute: Locate and select a specific digital twin using the unique identifier stored in the attributes.
        • Get objects from attributes:
          • Attribute of digital twin
          • Behavior tree attribute
          • Current attribute
        • Use ID to find digital twin
          • Digital twin ID
          • Attribute ID
      • All digital twins in the scene: Search for digital twins throughout the entire scene.
        • Method to filter digital twins: When using “All digital twins in the scene” as the base method for locating digital twins, different filtering methods can be used to precisely locate the desired digital twin.
          • None: No filtering conditions are used; search all digital twins in the scene.
          • Find in scene by ID: Search based on the unique ID of the digital twin. Each digital twin has a unique identifier (ID) upon creation.
          • Find the digital twin by minimum distance: Filter based on the distance between the digital twin and the digital twin executing the behavior tree, finding the closest digital twin.

Advanced method to find digital twins

      • None: No specific advanced methods.
      • Parent digital twin: Locate the parent digital twin of the current digital twin. For example, the parent digital twin of cargo on a conveyor belt is the conveyor belt itself.
      • The last child digital twin: Find the last child digital twin of the current digital twin. For example, the last product in a batch of generated products.
      • The first child digital twin: Find the first child digital twin of the current digital twin. For example, the first product in a batch of generated products.
      • All child digital twins: Locate all child digital twins of the current digital twin. For example, all products on a production line.
      • Previous digital twin: Find the previous sibling digital twin of the current digital twin. For example, the product before a certain product on a conveyor belt.
      • Next digital twin: Find the next sibling digital twin of the current digital twin. For example, the product after a certain product on a conveyor belt.

Find the type of object: Choose the target object to find, which can be either the digital twin itself or a specific element within the digital twin.

      • Digital twin: Choose to find the entire digital twin object for overall operations or to retrieve its attributes. For example, locating and operating a robot, a production line device, or a shelf unit.
      • Role in digital twin: Choose to locate specific roles within the digital twin. This type is used for operations on specific parts within the digital twin, such as a raw material generator’s digital twin template containing roles like the generator model, output port, and progress bar.

Method to get the position

Method of getting the position

      • Manual entry
      • Directly input the 3D coordinates of a point in the format x, y, z.
      • Example: Input “10,20,30” represents a specific spatial location.
      • Location of digital twin: Use the current location of the digital twin.
      • Attribute of digital twin: Obtain the location from the digital twin’s attributes.
      • Behavior tree attribute: Obtain the location from the attributes of the behavior tree.
      • Find the point in the path map by attribute: Use attribute values to find points in the path map.

Coordinate Types

      • Local coordinate: Coordinates relative to a reference point. For example, the local coordinates of goods on a conveyor belt are relative to the center point of the conveyor belt.
      • Coordinate: Global coordinate, or world coordinate.

Digital twin nodes

Digital twin nodes are used for creating, deleting, and manipulating digital twins and digital twin attributes.

Create digital twins

Function: Create a digital twin corresponding to a specified digital twin template with a given pose (position, rotation angle).

Example: Automatically generate products on a factory production line. The following example configures the “Create digital twin” node so that Digital twin A creates a new digital twin at its own output port.

    • The template used to create the digital twin
      • Method to get attributes: Select “Select attribute directly”
      • Get location: Select “Attribute of digital twin”
      • Attribute of digital twin: Choose “Template of Digital twin A” > “Identifier for Generating digital twin” (an attribute defined by the user in the template of Digital twin A for template identification).
    • Way of finding digital twin
      • Basic method to find digital twins: Select “Self”
    • Create the location of the digital twin
      • Method to get attributes: Select “Select attribute directly”
      • Get location: Select “Attribute of digital twin”
      • Attribute of digital twin: Select “Template of Digital twin A” > “Output port” > “Position of the output port”

Delete digital twin

Function: Delete a specified digital twin. For example, automatically remove products from the production line that have expired or are no longer needed.

Set attributes

Function: Set any attributes of a digital twin or behavior tree.

Set digital twin pose

Function: Set the position and rotation of a digital twin or elements within the digital twin. For example, adjust the position and angle of a robot arm to perform a specific task.

Set parent object of digital twins

Function: Set a digital twin as a child object of another digital twin.

Get digital twin

Function: Set a digital twin as the current digital twin or save the digital twin identifier to a target digital twin attribute.

Display or hide digital twin

Function: Display or hide a digital twin or elements within a digital twin.

Attribute change to Vector3

Function: Convert a certain attribute value into a three-dimensional vector (Vector3) format.

Delete elements in the container

Function: Remove an element from a specified container (such as a list or dictionary). Containers are attributes that can store and manage multiple elements. These attributes can contain other objects or basic data types and provide methods to access and manipulate these elements. The currently supported container types are List and Dictionary. For example, remove a specific product from a virtual warehouse containing multiple products.

Path nodes

Path nodes are used for configuring and controlling the moving path of digital twins.

Set digital twin moving path

Function: Save a specified path into the digital twin’s attributes.

Example: The following example demonstrates how to use the “Set digital twin moving path” node to set a movement path for items on a conveyor belt.

    • Digital twin to be moved
    • Specify a digital twin
      • Basic method to find digital twins: Select “Temporary digital twin”
      • Find the type of object: Select “Digital twin”
    • Target path
      • Method to get attributes: Select “Select attribute directly”
      • Get location: Select “Attribute of digital twin”
      • Attribute of digital twin: Select “Conveyor template”> “Configure Path” attribute
    • Way of finding digital twin
      • Basic method to find digital twins: Self
    • The starting point of the move: Current point
    • Set the moving speed of digital twin
      • Method to get attributes: Select “Select attribute directly”
      • Get location: Select “Attribute of digital twin”
      • Attribute of digital twin: Select “Conveyor template”> “Convey Speed” attribute
    • Way of finding digital twins
      • Basic method to find digital twins: Select “Self”
    • Keep the original rotation angle when entering the path: yes

Move digital twins along a path

Function: Move a specified digital twin along a given path. For example, specify a path, starting point, and movement speed for an AGV (Automated Guided Vehicle) so that it can move according to the set path and speed.

Move one step

Function: Move the target digital twin one step at the configured speed. For example, move an object on a conveyor belt one step to simulate the process of gradual movement of the object on the conveyor belt.

Generate path

Function: Set the current moving path attribute of a digital twin. For example, use the “Generate Path” node to configure the “Current moving path” attribute for a digital twin (such as a robot or AGV) and, in conjunction with the “Move digital twins along a path” node, allow the digital twin to move along the predefined path.

Track digital twins along the path

Function: Set the digital twin’s pursuit target, shortest path, and starting point to automatically navigate and chase the target digital twin. For example, a robotic arm grabbing a moving item on a conveyor belt.

Port nodes

Get digital twins from the input port

Function: Retrieve a digital twin from the input port and save it to a specified attribute.

Remove digital twins from the input port

Function: Delete the digital twin at the input port.

Set digital twins to the port

Function: Place the target digital twin at the specified port.

Storage node

Outbound sorting

Function: Move the specified digital twin out of the designated storage area.

Inbound sorting

Function: Place the specified digital twin into the designated storage area.

Role nodes

Play animation

Function: Play the specified animation of a role in the digital twin. By default, the animation plays once.

Example: The following example shows how to use the “Play Animation” node to play the “Pick and Move Object” animation for the “Six-Axis Robotic Arm.”

    • Target object
      • Basic method to find digital twins: Self
      • Find the type of object: Role in the digital twin
      • Target role ID: Six-Axis Robotic Arm
    • Animation control
      • Animation name: Pick and Move Object
      • Animation speed: 1(Normal speed)

Note:

      • The Target Role ID needs to be entered manually, which is the name of the model’s role; you can view it in the Template Editor.
      • The Animation Name needs to be entered manually; the model role must include this animation. You can view the specific animation name in DataMesh Importer.

Tool nodes

Idle

Function: Stop the execution of the behavior tree.

Example:

The following Idle node uses the condition “Check if digital twins already exist at the port” to determine when to stop the behavior tree. The behavior tree stops running when other digital twins are present at the port.

Log

Function: The log node is used to output specified text content, which is displayed in the “Output Information” panel in the scene playback interface.

Wait

Function: The wait node is used to pause the execution of the behavior tree until the waiting time has elapsed. Once the waiting time ends, the behavior tree will continue to execute the nodes following the wait node.

Behavior tree nodes

Add behavior tree

Function: Add the target behavior tree to the target digital twin.

Remove behavior tree

Function: Remove the target behavior tree from the target digital twin.

Math nodes

Math nodes are used to perform various mathematical operations and apply the results to digital twin attributes.

Sin Function

Function: Convert the input value to the corresponding sine value and output it.

Cos Function

Function: Convert the input value to the corresponding cosine value and output it.

Tan Function

Function: Convert the input value to the corresponding tangent value and output it.

Orthostatic Distribution

Function: Generate output values based on a normal distribution using the input value.

Poisson Distribution

Function: Generate output values based on a Poisson distribution using the input value.

Radom number

Function: Output a random number.

Addition

Function: Select two attribute values of the digital twin for addition, and either replace a specific attribute value of the digital twin with the result or add the result to it.

Subtraction

Function: Select two attribute values of the digital twin for subtraction, and either replace a specific attribute value of the digital twin with the result or add the result to it.

Multiplication

Function: Select two attribute values of the digital twin for multiplication, and either replace a specific attribute value of the digital twin with the result or add the result to it.

Division

Function: Select two attribute values of the digital twin for division, and either replace a specific attribute value of the digital twin with the result or add the result to it.

Event nodes

Receive event

Function: Used to listen for and respond to a specified event. Only one digital twin can listen for and respond to this event. For example, if two AGVs need to compete for the same cargo, the receive event node can be used to ensure that only one AGV responds to the cargo arrival event, avoiding conflicts.

Send event

Function: Send a specified event to trigger actions or behaviors in other digital twins. For example, on a production line, after one processing step is completed, an event can be sent to notify the next processing step’s digital twin to start working.

Node condition

Definition

Node conditions can be added to composite nodes and action nodes, referring to the conditions that need to be met for the node to execute. If the conditions are met, the node executes; if not, it does not execute and returns to the parent node.

    • Condition : A single condition.
    • Condition Group : Conditions within a condition group are combined with an “AND” relationship. This means that the node can only execute if all conditions within the group are met.
    • Multiple condition groups : A node can have multiple condition groups. These groups are combined with an “OR” relationship. This means that if any one of the condition groups is met, the node can execute.

Common conditions

Check if digital twins already exist at the port

This condition is used to determine whether other digital twins are present at the ports of a digital twin.

Configure parameters

    • Target port: Set the port to be checked.
      • Digital twin at the port: Specify which digital twin’s port needs to be checked.
        • Basic method to find digital twins: Select the basic method to find digital twins.
        • Advanced method to find digital twins: Select the advanced method to find digital twins.
        • Port name: Select the specific port to be checked.

Example

The following example checks whether there are other digital twins at the input port of the digital twin executing the behavior tree.

Compare attributes of two digital twins

This condition is used to compare specific attribute values of two digital twins to determine if a particular condition is met. Perform corresponding behavior logic based on the comparison result.

Configure parameters

    • Source attribute
      • Method to get attributes: Select how to get the source attribute.
      • Get location: Set the method for getting the source attribute.
      • Way of finding digital twins: Choose how to find the digital twin.
    • Target attribute
      • Method to get attributes: Select how to get the target attribute.
      • Get location: Set the method for getting the attribute value.
      • Way of finding digital twins: Choose how to find the digital twin.
    • Comparison method:
      • Equal to: The source attribute value is equal to the target attribute value.
      • Greater than: The source attribute value is greater than the target attribute value.
      • Less than or equal to: The source attribute value is less than or equal to the target attribute value.
      • Greater than or equal to: The source attribute value is greater than or equal to the target attribute value.
      • Not equal to: The source attribute value is not equal to the target attribute value.

Example

Assuming we need to compare the “positions” of two digital twins, A and B, to see if they are the same, the following steps can be set up:

    1. Source attribute
    • Method to get attributes: Select “Select attribute directly”
    • Get Location:  Select “Attribute of digital twin”
      • Attribute of digital twin:  Select “Position” attribute in the Digital Twin A template
    • Basic method to find digital twins: Select “Self”, which means the Digital Twin A executing the behavior tree.
    1. Target attribute:
    • Method to get attributes: Select “Select attribute directly”
    • Get Location:  Select “Attribute of digital twin”
      • Attribute of digital twin:  Select “Position” attribute in the Digital Twin B template
    • Way of finding digital twins:
      • Basic method to find digital twins: Select “All the digital twins in the scene”
      • Method to filter digital twins: select “Find in scene by ID”
      • Use ID to find digital twin: Select “Digital twin ID”
      • Value: “Digital Twin B”
    1. Comparison method: Select “Equal to”

Check the distance between two points

Compare the distance between two points and perform corresponding actions based on the comparison result of the distance reference value.

Configure parameters

    • First point
      • Method of getting the position: how to get the position of the first point.
        • Manual entry: Directly input the 3D coordinates of the point in the format x, y, z.
        • Location of digital twin: Use the position of the digital twin as the position of the first point.
        • Attribute of digital twin: Retrieve the position from the attributes of the digital twin.
        • Behavior tree attribute: Obtain the position from the attributes of the behavior tree.
        • Find the point in the path map by attribute: in the Use attribute values to find points in the path map.
      • Coordinate Type: Choose the type of coordinate to use.
        • Local coordinate: Coordinates relative to a reference point. For example, the local coordinates of goods on a conveyor belt are relative to the center point of the conveyor belt.
        • Coordinate: Global coordinate, or world coordinate.
      • Way of finding digital twins: Choose the method for finding the digital twin.
    • Second point
      • Method of getting the position: how to get the position of the second point.
      • Coordinate Type: Choose the type of coordinate to use, Local coordinate or Coordinate.
      • Way of finding digital twins: Choose the method for finding the digital twin.
    • Reference distance value
      • Method to get attributes: Choose the method for obtaining the reference distance value.
      • Get location: Choose from where to obtain the reference distance value.
    • Comparison method: Select the comparison method to determine the relationship between the distance of two points and the reference value.
      • Equal to: The distance between the two points is equal to the reference value.
      • Less than: The distance between the two points is less than the reference value.
      • Greater than: The distance between the two points is greater than the reference value.
      • Less than or equal to: The distance between the two points is less than or equal to the reference value.
      • Greater than or equal to: The distance between the two points is greater than or equal to the reference value.
      • Not equal to: The distance between the two points is not equal to the reference value.

Example

Assuming we need to determine whether the distance between two temporary digital twins (products) A and B on a conveyor belt is less than a specified safety distance, follow these steps for configuration:

    1. First point
      • Method of getting the position: Select “Location of digital twin”
      • Coordinate type: Select “Local coordinate”
      • Basic method to find digital twins: Select “Temporary digital twin”, that is Digital Twin A
    2. Second point
      • Method of getting the position: Select “Location of digital twin”
      • Coordinate type: Select “Local coordinate”
      • Basic method to find digital twins: Select “Temporary digital twin”
      • Advanced method to find digital twins: Select “The last digital twin”, that is Digital Twin B.
    3. Reference distance value
      • Method to get attributes: Select “Select attribute directly”
      • Get location: Select “Manual entry”
      • Manual entry: “1”
    1. Comparison method
      • Select “Less than”

Check if there is a digital twin in the storage area

This condition is used to determine if there are any objects present in the specified storage area.

Configure parameters

    • Target storage: Specify the target storage area.
      • Digital twin which belongs to the storage: Used to specify the digital twin belonging to the storage area.
        • Basic method to find digital twins: Choose the basic method for locating the digital twin belonging to the storage area.
        • Advanced method to find digital twins: Further refine the search for the digital twin belonging to the storage area.

Example

The following example determines whether there are objects in the storage area of the digital twin executing the current behavior tree.

Check if the digital twin can be placed in the storage area

Determine if a certain twin body can be placed in the specified storage area.

Configure parameters

    • Target Storage: Specify the target storage area.
      • Digital twin which belongs to the storage: Used to specify the digital twin belonging to the storage area.
        • Basic method to find digital twins: Choose the basic method for locating the digital twin belonging to the storage area.
        • Advanced method to find digital twins: Further refine the search for the digital twin belonging to the storage area.
      • Digital twin to be stored:
        • Basic method to find digital twins: Choose the basic method for locating the digital twin to be stored.
        • Advanced method to find digital twins: Further refine the search for the digital twin to be stored.

Example

Assuming we need to determine whether a certain item can be placed in the storage area of the Digital Twin A executing the behavior tree, the setup can be done as follows:

    1. Target storage
    • Digital twin which belongs to the storage
      • Basic method to find digital twins: Select “Self”
    1. Digital twin to be stored
    • Basic method to find digital twins: Select “Temporary digital twin”

Check if the digital twins are the same

This condition is used to determine whether two digital twins are the same.

Configure parameters

    • Compare digital twins
      • Basic method to find digital twins: Choose how to find the digital twin for comparison.
      • Advanced method to find digital twins: Further refine the search for the digital twin for comparison (e.g., by filtering based on specific conditions).
    • Specify a digital twin ID
      • Way of finding digital twins: Choose how to find the digital twins for comparison.

Edit behavior tree

Basic method

The basic process of editing a behavior tree can be divided into the following steps:

1. Function decomposition

Break down complex functions into multiple independent sub-functions. For example, a material generator can be decomposed into two sub-functions: “Production” and “Output.”

2. Prepare digital twin templates
a) Create digital twin template
b) Add resources: Based on the results of the function decomposition, add resources for each specific goal of the sub-functions. For example, the production function of the material generator requires an outlet to output the generated items.
c) Set attributes: Configure the relevant attributes for each sub-function. For example, for the production function of the material generator, set the production interval and the template required for producing items.

3. Edit the Behavior Tree: Use the behavior tree editor to define the specific behavior logic for each sub-function. For instance, the production function of the material generator can be set to produce items at regular intervals (wait node) and create digital twins (create twin body node). The output function can use Set Digital Twins to the Port Node to send goods to the outlet.

Example

Basic functions of the Source

1. Function decomposition: “Production” and “Output.”

2. Prepare digital twin template:
a) Create a digital twin template: Create a twin template and add a Source model to the template (“/Public Directory/FactVerseDLC/ChuangJianQi_DLC”).
b) Add resources: Add an “Output” to the production function of the Source.

c) Set attributes:
i. In the Digital Twin Template pane, click the ︙next to Metadata and select Add structure to add “Part_1.”
ii. Set production interval attribute: Under “Part_1,” add a “Production Interval” (Double type) attribute with the following settings:

    • Unit: “s”
    • Default value: “3”
    • Check the option “Show in the digital twin.” When checked, users can edit this attribute in the scene editor when using this template to generate digital twins.

iii. Set template ID attribute for production items: Under “Part_1,” add a “Generated Digital Twin Identifier” (String type) property with the following settings:

    • Purpose: Select “Digital twin template”
    • Check the option “Show in the digital twin.”

iv. Save template: Click the “Save” button on the toolbar to save the template.

3. Edit behavior tree:
a) Create behavior tree:
i. In the Digital Twin Template pane, click the︙ next to the Behavior Tree section and select “Create Behavior Tree.”

ii. In the opened window, choose the storage path and enter the Behavior Tree name.

iii. Click the “New” button to complete the creation of the Behavior Tree.
iv. Click the “Save” button on the toolbar to save the template.

b) Edit behavior tree: The newly created Behavior Tree “Behavior tree of Source” only contains a root node. The following steps will add nodes and running conditions to the “Behavior tree of Source.”
i. In the Digital Twin Template pane, double-click the newly created “Behavior tree of Source” under the Behavior Tree section to open the Behavior Tree Editor.
ii. Add a Selector node and connect the Root node with the Selector node. For connection methods, refer to the section Node operations.

iii. Add an Idle node and connect the Selector node with the Idle node. Set the running conditions of the Idle node to stop when production items are present at the output.

iv. Add a Sequence node and connect the Selector node with the Sequence node.

v. Add a Wait node and connect the Wait node with the Sequence node. Set the attributes of the Wait node:

    • Waiting time
      • Get location: Attribute of digital twin
      • Attribute of digital twin: Production interval

vi. Add a node for producing items: Add a Create Digital Twin node, connect the Sequence node with the Create Digital Twin node, and set the attributes of the Create Digital Twin node:

    • The templated used to create the digital twin
      • Method to get attributes: Select attribute directly
      • Get location: Attribute of digital twin
      • Attribute of digital twin: Produced Digital Twin Identifier
    • Create the location of the digital twin
      • Method to get attributes: select attribute directly
      • Get location: Attribute of digital twin
      • Attribute of digital twin: Source Template > Output port_1> The location of the port

vii. Add a Set Digital Twins to the Port node: Connect the Sequence node with the Set Digital Twins to the Port node, and set the attributes of the node:

    • Target port
      • Digital twin at the port
        • Basic method to find digital twins: Self
      • Port name: Source Template > Output port_1
    • Set the digital twin to the port: “Temporary digital twin”

viii. Click the “Save” button on the toolbar to save the Behavior Tree.

Moving ball

1. Create a Ball Twin Template:
a) Click on New Template in the homepage to open the template editor.
b) Drag the “Sphere” from Libraries into the scene area and adjust its position.
c) Change the color of the ball to green.

d) Click the save button on the toolbar and save the template as “Moving Ball.”

2. Add main function structure to “Moving Ball” Template:

a) In the Digital Twin Template pane, click the ⋮ next to Metadata and select Add Structure.
b) Scroll down to find the newly added structure “Part_1,” click on it, and change the structure name in the attributes area to “Main Function.”
c) Under the “Main Function” structure, add a “Real-time Position” (Vector3) attribute.

3. Add behavior tree for moving ball:
a) In the Digital twin template pane, click the ⋮ next to Behavior Tree and select Create Behavior Tree.
b) Save the behavior tree and name it “Move the ball.”

4. Edit behavior tree logic

a) Double-click the “Move the ball” behavior tree to open the behavior tree editor.
b) Add a Sequence node under the Selector Node.
c) Under the Sequence node, add a Set Digital Twin Pose node “Set Digital Twin Pose 1” and configure the attributes as follows:

Specify a digital twin

    • Basic method to find digital twins: Self
    • Find the type of object: Digital twin

Set the position of the digital twin

    • Method to get attributes: Select attribute directly
    • Get location: Manual entry
    • Manual entry: 0.5,0,0

d) Add a Wait node “Wait 1” under the Sequence node and set the Manual entry value for wait time to “0.5.”

e) Add another Set Digital Twin Pose node:
i. Copy “Set Digital Twin Pose 1” using CTRL+C and paste it with CTRL+V under the Sequence node to create a new Set Digital Twin Pose node “copy_Set Twin Pose 1.”
ii. Rename it to “Set Digital Twin Pose 2.”
iii. Change the Manual entry for Set the position of the digital twin to “0.5,0,-0.5.”

f) Copy “Wait 1” node using CTRL+C and paste it with CTRL+V to create a new wait node “copy_Wait 1,” renaming it to “Wait 2.”

g) Add a “Set Digital Twin Pose 3” node by copying “Set Twin Pose 1,” changing the manual input for Set the position of the digital twin to “0,0,-0.5.”

h) Copy “Wait 1” node again using CTRL+C and paste it with CTRL+V to create a new wait node “copy_Wait 1,” renaming it to “Wait 3.”

i) Click the Save button on the toolbar to save the behavior tree.
j) Click the < button to exit the behavior tree editor.
k) Save the “Moving Ball” template and click the homepage button to exit the template editor.

5. Create a scene and add a moving ball in the scene

a) Create a new scene named “Moving Ball.”
b) Use the “Moving Ball” template to create a “Moving Ball 1” digital twin.
c) Add “Moving Ball 1” to the scene.

d) Play the scene to preview the ball’s movement.

Response to the signal to change the color of the cube

In this example, we will use event nodes to listen for and respond to events, changing the color attribute of a cube.

Prerequisites

Please prepare the “Color-Changing Cube” template by following the steps in the Create a brand-new template section.

1. Create a Sphere Digital twin template:

a) Click on New Template in the homepage to open the template editor.
b) Drag the “Sphere” from Libraries into the scene area and adjust its position.

c) Click the save button in the toolbar and save the template as “Signal-Sending Sphere.”

2. Add main function structure to “Signal-Sending Sphere” template:
a) In the Digital Twin Template pane, click ︙ next to Metadata and select “Add Structure.”
b) Scroll down to find the newly added structure “Part_1,” click on it, and change its name to “Main Function” in the properties area.
c) Under the “Main Function” structure, add a “Signal” (Int) attribute.

3. Add Behavior Tree for “Signal-Sending Sphere”:
a) In the Digital Twin Template pane, click ︙ next to the behavior tree section and select “Create Behavior Tree.”

b) Save the behavior tree and name it “Send Signal.”

4. Edit behavior tree logic: In this example, three signals “100,” “200,” and “300” will be sent.
a) Double-click on the “Send Signal” behavior tree to open the behavior tree editor.
b) Add a Sequence node under the Root node and use the default attributes.
c) Under the Sequence node, add a Send Event node “Send Signal 100,” and set its attributes as follows:

    • Event type
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 100

d) Add a Wait node “Wait 1” under the Sequence node and set the manual entry wait time to “2.”
e) Add the “Send Signal 200” node:
i. Copy and paste the “Send Signal 100” node; it will automatically be added under the Sequence node.
ii. Rename it to “Send Signal 200.”
iii. Reconnect the Sequence node and the “Send Signal 200” node.
iv. Change the manual entry value for the Event type in the “Send Signal 200” node to “200.”
f) Add a Wait node “Wait 2” and set the manual entry wait time to “2”.
g) Add the “Send Signal 300” node:
i. Copy and paste the “Send Signal 100” node; it will automatically be added under the Sequence node.
ii. Rename it to “Send Signal 300.”
iii. Reconnect the Sequence node and the “Send Signal 300” node.
iv. Change the manual entry value for the Event type in the “Send Signal 300” node to “300.”
h) Add a Wait node “Wait 3” and set the manual entry wait time to “2”.
The following image shows the complete behavior tree structure:

i) Save the behavior tree and exit the behavior tree editing interface.
j) Save the template and return to the homepage.

5. Add a Behavior Tree for the “Color-Changing Cube” template to receive signals and change color:

a) Open the “Color-Changing Cube” template.
b) Change the cube’s color to white.
c) Create a new “Event Response” behavior tree in the template.
d) Double-click the “Event Response” behavior tree to open the editing interface.
e) Add a Parallel node under the Root node.
f) Add a Sequence node “Sequence Node 1” under the Selector node.
g) Add a Receive event node “Receive Signal 100” under “Sequence Node 1” and set the attributes as follows:

    • Event type
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 100

h) Add a Set attributes node “Set Signal” under “Sequence Node 1” and set the attributes as follows:

    • Target attribute
      • Method to get attributes: Select attribute directly
      • Attribute source: Attribute of digital twin
      • Strategy for setting value: Replace the original value
      • Attribute of digital twin: Singal (the “Signal” attribute of the “Color-Changing Cube” template)
    • Target attribute value
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 100

i) Add a Set attributes node, rename it to “Set Color”, and set the attributes as follows:

    • Target attribute
      • Method to get attributes: Select attribute directly
      • Attribute source: Attribute of digital twin
      • Strategy for setting value: Replace the original value
      • Attribute of digital twin: Color (the “Color” attribute of the “Color-Changing Cube” template
      • Specify a digital twin
        • Basic method to find digital twins: self
    • Target attribute value
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 255,254,145,10 (corresponding color is       )

j) Add a Sequence node “Sequence Node 2” under the Selector node.
k) Add a Receive event node “Receive Signal 200” under “Sequence Node 2” and set the attributes as follows:

    • Event type
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 200

l) Add a Set attributes node “Set Signal” under “Sequence Node 2” and set the attributes as follows:

    • Target attribute
      • Method to get attributes: Select attribute directly
      • Attribute source: Attribute of digital twin
      • Strategy for setting value: Replace the original value
      • Attribute of digital twin: Singal (the “Signal” attribute of the “Color-Changing Cube” template)
    • Target attribute value
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 200

m) Add a Set attributes node under “Sequence node 2”, rename it to “Set Color”, and set the attributes as follows:

    • Target attribute
      • Method to get attributes: Select attribute directly
      • Attribute source: Attribute of digital twin
      • Strategy for setting value: Replace the original value
      • Attribute of digital twin: Color (the “Color” attribute of the “Color-Changing Cube” template
      • Specify a digital twin
        • Basic method to find digital twins: self
    • Target attribute value
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 100,100,200,200 (corresponding color is     )

n) Add a Sequence node “Sequence Node 3” under the Selector node.
o) Add a Receive event node “Receive Signal 300” under “Sequence Node 3” and set the attributes as follows:

    • Event type
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 300

p) Add a Set attributes node “Set Signal” under “Sequence Node 3” and set the attributes as follows:

    • Target attribute
      • Method to get attributes: Select attribute directly
      • Attribute source: Attribute of digital twin
      • Strategy for setting value: Replace the original value
      • Attribute of digital twin: Singal (the “Signal” attribute of the “Color-Changing Cube” template)
    • Target attribute value
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 300

q) Add a Set attributes node under “Sequence node 3”, rename it to “Set Color”, and set the attributes as follows:

    • Target attribute
      • Method to get attributes: Select attribute directly
      • Attribute source: Attribute of digital twin
      • Strategy for setting value: Replace the original value
      • Attribute of digital twin: Color (the “Color” attribute of the “Color-Changing Cube” template
      • Specify a digital twin
        • Basic method to find digital twins: self
    • Target attribute value
      • Method to get attributes: Select attribute directly
      • Get location: Manual entry
      • Manual entry: 255,100,100,100 (corresponding color is    )

The following image shows the complete behavior tree structure:

r) Click the Save button in the toolbar to save the behavior tree.
s) Click < to exit the behavior tree editor.
t) Save the template and return to the homepage.

6. Create a New Scene Named “Event Response”.

7. Add a Sphere that can send events and two Cubes that can receive events in the scene:
a) Create two cubes “Cube 1” and “Cube 2” using the “Color-Changing Cube” template.
b) Create a “Signal Sending Sphere 1” using the “Signal-Sending Sphere” template.
c) Add “Cube 1”, “Cube 2”, and “Signal Sending Sphere 1” to the scene.

8. Save the scene.

9. Play the scene.

Chasing a moving ball

This example demonstrates how to create a cube digital twin in a virtual scene and implement behavior tree logic to have it automatically chase a moving ball.

1. Create a cube digital twin template:
a) Click New Template on the homepage to enter the template editor.
b) Drag the “Cube” from the tool pane into the scene area and adjust its position.
c) Click the save button in the toolbar and name the template “Chasing Target Cube.”

2. Add Behavior Tree for Chasing Target Cube:
a) In the Digital Twin Template pane, click ︙ next to the Behavior Tree section and select “Create Behavior Tree.”
b) Save the behavior tree and name it “Chasing Target Cube.”

3. Edit behavior tree logic
a) Double-click the “Chasing Target Cube” behavior tree to open the behavior tree editor.
c) Add a Sequence node under the Root node.
d) Under the Sequence node, add a Track digital twins along the path node and configure the following attributes:

    • Save the path to
    • Method to get attributes: Select attribute directly
    • Source attribute: Attribute of digital twin
    • Strategy for setting value: replace the original value
    • Attribute of digital twin: Current moving path(“Current moving path” attribute of “Chasing Target Cube”)
    • Start point
    • Method to get attributes: Select attribute directly
    • Get location: Manual entry
    • Manual entry: point0
    • Target to be chased
      • Specify a digital twin
        • Basic method to find digital twins: All the digital twins in the scene
        • Method to filter digital twins: Find in scene by ID
        • Get objects from attributes: Attribute of digital twin
        • Use ID to find digital twin: Digital Twin ID
        • Value: 1599. (ID of “Moving Ball 1” in the Example Moving ball, you can check the ID in its digital twin attribute pane )
        • Find the type of object: Digital twin

    e) Under the Sequence node, add a Move digital twins along a path node and configure the following attributes:

      • Set path
        • Method to get attributes: Select attribute directly
        • Get location: Attribute of digital twin
        • Attribute of digital twin: Current moving path(“Current moving path” attribute of “Chasing Target Cube”)
      • Set speed:
        • Target speed: “10”

    f) Click the save button in the toolbar to save the behavior tree.
    g) Click < to exit the behavior tree editor.
    h) Save the “Chasing Target Cube” template, then click the homepage button to exit the template editor.

    4. Create a Scene: Create a new scene named “Chasing Moving Ball.”

    5. Add a Chasing Target Cube and a Moving Ball to the Scene:
    a) Use the “Chasing Target Cube” template to create “Chasing Target Cube 1” and add it to the scene at position “0,0,0.”

      b) Use the “Moving Ball” template to create “Moving Ball 1” and add it to the scene at position “0.5,0,-0.5.”

      6. Create a path connecting four points:
      a) Hide “Chasing Target Cube 1” and “Moving Ball 1” to prevent obstruction while creating the path points, ensuring accurate placement.

        b) Enter the path planning interface, use the build mode to create the following four points and connect them. These points will form the movement path for “Chasing Target Cube 1,” where “point0” is the starting point. The cube will calculate the shortest path to chase “Moving Ball 1.”

          • point0 (0,0,0)
          • point1 (0.5,0,0)
          • point2 (0.5,0,-0.5)
          • point3 (0,0,-0.5)

        c) Switch to selection mode and change the connection direction to bidirectional.

        d) Save the path and exit the path planning interface.
        e) Switch “Chasing Target Cube 1” and “Moving Ball 1” back to display status.

        7. Save the Scene.

        8. Play the Scene: “Chasing Target Cube 1” will chase “Moving Ball 1” along the shortest path.

        Table of Contents