Databrain - FAQ

DataObjectDropdown Attribute

Can I add a DataObjectDropdown attribute inside a DataObject class to reference other DataObjects inside of the Databrain editor?

Yes absolutely. Simply add the [DataObjectDropdown] attribute without any additional parameter. The library will be found automatically.

Can I use a return method instead of a name as the DataLibrary parameter in the DataObjectDropdown attribute?

Yes, you can! This is a great way when you have a singleton class which holds the DataLibrary in your scene. Here's an example code:

// Simply add the name of the DataLibrary returning method
[DataObjectDropdown(nameof(GetLibrary))]
public MyDataObject myDataObject;

public DataLibrary GetLibrary()
{
    return DataManager.Instance.data;
}

This would require a singleton of type DataManager which looks like this: Please note that you should also add the OnValidate method so that the DataLibrary will be found in the editor (not only at runtime).

// SINGLETON Example
// Please make sure to add the OnValidate method like in this example
// to your singleton class.
public class DataManager : MonoBehaviour
{
    public static DataManager Instance { get; private set; }

    public DataLibrary data;
    
    
    private void OnValidate()
    {
        Instance = this;
    }

    public void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(this);
            return;
        }

        Instance = this;
    }
}
Does the DataObjectDropdown support sub-types?

Yes, simply set the includeSubtypes parameter to true:

[DataObjectDropdown(includeSubtypes: true)]
public MyDataObject dataObject;
My DataObjectDropdown doesn't show up. All I see is a No GUI Implemented label.

This mostly happens because of another third-party asset installed. Please check out following page for a possible fix.

No GUI Implemented - FIX

General

My properties (get; set;) won't show up in the DatabrainEditor

The reason for this is that when you declare a property like public int Speed {get; set;} a hidden backing field is generated by the compiler which is where the value is actually stored, this field is private and so will not be serialized automatically by Unity's serializer. C# 7.3 added Auto-implemented property field-targeted attributes, allowing you to do this:

[field:SerializeField] public int Speed {get; set;}

This will apply the SerializeField attribute to the hidden generated field and Unity should serialize it normally.

How can I enable Odin Inspector attribute support inside of the Databrain editor?

Simply use the [UseOdinInspector] attribute to your DataObject class.

Last updated