Blackboard

The blackboard add-on is included by default in the Databrain package

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>

public class BooleanVariable : BlackboardGenericVariable<bool> {}

Custom enum:

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

Value

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.

Example code:

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:

public class BlackboardExample : MonoBehaviour
{
    public DataLibrary data;

    [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);
    }
}

Last updated