Aller au contenu

Using behavior graphs

After having introduced the behavior graph system, nodes, connectors and connections, it is appropriate to see more in depth the possibilities offered by the graph system, but first let's see how to use a graph.

Assigning a graph to an entity

A large number of entities are compatible with behavior graphs and can use programmed behaviors. In fact, any entity that is not a list can use one or more behavior graphs.

To associate a graph with an entity, simply go to the Attributes and Behaviors tab of the entity in question.

Image title 2

The Attributes and Behaviors tab

In this tab, one or more behavior graphs can be assigned.

Image title 2

The function to assign a behavior graph to the entity

Image title 2

The behavior graph added

Graph variables

As in any computer program, it may be necessary to store a value at a moment T to be able to reuse it later in the graph. For this, the graph system allows the creation of variables that are stored within the graph itself.

Image title 2

A comment node including the start node and a short text.

There are several types of variables:

  • Bool (Boolean variable)
  • Color (4 component color variable)
  • InputKey (Keyboard key variable)
  • Number (Double precision numeric variable)
  • String (Text variable)
  • Vector 2 (Two-component numeric variable)
  • Vector 3 (Variable with three numeric components)

Handling of variables

Variables can be used via two nodes, the "Set Variable Value" and the "Get Variable Value". Both of these nodes require an internal configuration of the variable name to be used.

Image title 2

A comment node including the start node and a short text.

Owner of the behavior and access to entities

The interest of a graph used by an entity is to be able to make reference to the other entities of the protocol. This is not done directly, it is not possible to make a direct reference to an entity from a graph, the graph must dynamically find the reference during its execution. For this purpose, the graph system provides a large number of accessibility nodes, which allow to browse the protocol tree up or down:

  • Get Owner (Get the entity on which the graph is assigned)
  • Get Parent (Get the parent of the entity passed in parameter)
  • Get Current Trial (Get the current trial entity)
  • Get Current Experiment (Get the current Experiment entity)
  • Get Protocol (Get the Protocol entity)
  • Get Child By Name (Get a child entity of the entity passed in parameter by indicating its name)
  • Get Children(Get all children of the entity passed in parameter as a list)

Image title 2

Entity access nodes.

The Owner

We are assured that the graph has an owner, therefore, the GetOwner node must be the main access gateway to the protocol entities. This node is so important that it is added natively when creating a new graph.

Property control

The graph system provides a set of nodes for accessing the properties of objects. A certain number of nominative nodes allow the control of the properties of an entity, it is for example the case of the nodes of textual control "Set 2D Text" and "Get 2D Text".

However, knowing that there is only one generic connector for the entities, it can be interesting to access the unexposed properties of a given entity. Properties are accessed by giving the name of the property.

Image title 2

The generic property access node.

The use of object attributes

So far, we have seen how to design behavior graphs that work independently of the entity on which they are assigned. Since the variables are integrated into the behavior, it is not possible, a priori, to vary the behavior of a graph according to the assigned entity.

This is where the entity attributes come in. It is indeed possible to use the attributes of entities within behavior graphs. Thus, it is possible to externalize some graph parameters by deporting them to the entity. It is thus possible to create behaviors that use data that are attached to the owner and not to the graph itself. It is thus possible to create, for example, a generic graph of sinusoidal displacement in which the amplitude and frequency are externalized on the object. The same graph applied to two objects can allow a different movement on both simply by changing the value of the attributes of the entity.

To do this, it is necessary to declare the attributes with the desired names and values. Thereafter, several nodes are used to obtain the values of the attributes depending on the type of attribute.

Image title 2

Entity attribute access nodes.

Access to attributes of other entities.

Actually, the access to attributes is not limited to the owner entity (obtained by a "Get Owner"), but to any entity as long as we have its reference as input parameter.

Image title 2

Example of attributes used in associated graphs.