# Behavior Graph

Unity’s **Behavior Graph** provides a powerful and visual way to design and manage behaviors within your projects. Here is a guide to getting started with it in a realvirtual.io context.

You can find a Demo scene here: Assets/realvirtual/BehaviorGraph/DemoBehaviorGraph.unity

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-0b0ba6c0b266086ddf3f7a522da35f0406243af0%2Fbehavior-graph.png?alt=media" alt=""><figcaption><p>Behavior Graph in the Behavior Demo Scene</p></figcaption></figure>

## Prerequisites and Installation

* **Install Behavior Graph**:
  * Open Unity and go to **Window > Package Manager**.
  * Locate **Behavior** in the list of available Unity packages.
  * Select and install the package.
*

```
<figure><img src="../../.gitbook/assets/visualscripting-bahaviorpackage.png" alt=""><figcaption></figcaption></figure>
```

* **Set Up Scripting Define Symbols**:
  * Navigate to **Edit > Project Settings > Player**.
  * Under the **Other Settings** section, locate **Scripting Define Symbols**.
  * Add `REALVIRTUAL_BEHAVIOR` to the list of symbols.
  * Save and close the settings.

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-9925eb76d400d87273159f3c85f080f02670ea45%2Fbehavior-playersettings.png?alt=media" alt=""><figcaption></figcaption></figure>

## Editing a Behavior Graph

The Behavior Graph allows you to visually design behavior flow for your Unity components.

For more detailed information on Unity's Behavior Graph system, refer to the Unity Documentation on Behavior Graphs.

{% embed url="<https://docs.unity3d.com/Packages/com.unity.behavior@1.0/manual/index.html>" %}

**Creating a New Behavior Graph**:

* Right-click in the **Project** window and select **Create > Behavior Graph**.
* Name your new graph file.

**Assigning the Behavior Graph**:

* Add a **Behavior Agent** component to a GameObject in your scene.
* Assign the newly created graph file to the component.

#### Using Behavior Graphs Across Scenes

* **Behavior Graphs are reusable**: You can use the same behavior graph across multiple scenes by attaching it to different objects.
* **Scene-specific connections**: To connect the graph variables to scene objects, you must link them in the **Behavior Agent** (see below).

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-1e4af304312cf0190a4a1795300110b1c06c00c7%2Fbehavior-agent.png?alt=media" alt=""><figcaption></figcaption></figure>

**Opening the Graph Editor**:

* Double-click the graph file in the **Project** window to open the Behavior Graph Editor.

**Adding Nodes**:

* Right-click anywhere in the graph editor to open the context menu.
* Select the type of node you want to add. There are several special realvirtual.io Nodes available.

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-91fbf38884e551d9b0103e0f9dbae4981f8ea98b%2Fbehavior-add.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-8eb4f9e6b6738b37f7f8ddb53b09d267c862b3ad%2Fbehavior-realvirtual.png?alt=media" alt=""><figcaption></figcaption></figure>

* Drag connections between nodes to define the behavior flow.

**Configuring Nodes**:

* Select a node to view its properties in the **Inspector** window.
* Configure properties like triggers, conditions, or actions for each node.

**Testing the Behavior**:

* Save the graph and play the scene to test your behavior.
* Debugging tools in Unity can help you monitor node activations and transitions.

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-8eb4f9e6b6738b37f7f8ddb53b09d267c862b3ad%2Fbehavior-realvirtual.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.realvirtual.io/components-and-scripts/defining-logic/behavior-graph.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
