# 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>
