# Blackboard

{% hint style="info" %}
The blackboard add-on is included by default in the Databrain package
{% endhint %}

The blackboard add-on supports the following types by default:

* Boolean
* Float
* Float List
* Integer
* Integer List
* String
* Vector2
* Vector3
* Prefab (GameObject)

## Add Types

You can easily add additional types by inheriting from BlackboardGenericVariable\<T>

```csharp
public class BooleanVariable : BlackboardGenericVariable<bool> {}
```

Custom enum:

```csharp
public class EnumVariable : BlackboardGenericVariable<MyEnum>
{
    public enum MyEnum
    {
        A = 0,
        B = 1,
        C = 2
    }
}
```

## Value

{% hint style="info" %}
When getting the value of a blackboard variable you will automatically receive the runtime value. **You don't have to call GetRuntimeDataObject() on the blackboard variable object.**
{% endhint %}

Example code:

```csharp
public class BlackboardExample : MonoBehaviour
{
    public DataLibrary data;

    [DataObjectDropdown("data")]
    public FloatVariable floatValue;
    
    public void Start()
    {
        data.RegisterInitializationCallback(Ready);
    }
    
    void Ready()
    {
        // Modify data directly (changes the runtime value)
        floatValue.Value += Time.deltaTime;
        
        // Get initial value
        var _initialData = floatValue.GetInitialDataObject();
        
    }
}
```

## On Value Changed

You can assign a blackboard event to a blackboard variable which gets called when the value has been changed. See the following example:

<pre class="language-csharp"><code class="lang-csharp">public class BlackboardExample : MonoBehaviour
{
<strong>    public DataLibrary data;
</strong>
    [DataObjectDropdown("data")]
    public FloatVariable floatValue;
    
    public void Start()
    {
        data.RegisterInitializationCallback(Ready);
    }
    
    void Ready()
    {
        floatValue.onValueChanged.RegisterListener(FloatChanged);
    }
    
    void FloatChanged(BlackboardVariable _variable)
    {
        // Float value has been changed
        var _value = (_variable as FloatVariable).Value;
        Debug.Log("New value: " + _value);
    }
}
</code></pre>


---

# 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://giantgrey.gitbook.io/databrain/add-ons/blackboard.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.
