Get initial data

Accessing data at runtime can be done in several ways.

Please note that you should only modify runtime-DataObjects at runtime. Those runtime-DataObjects are being serialized when saving to a file. See -> Add data objects at runtime

Get initial data by referencing the data object

The simplest way would be to reference your data object in your script so let’s assume we have an EnemyData object which looks like this:

public class EnemyData : DataObject
{
    public int health;
}

Now, in our Monobehaviour script, we can add the following reference:

public class Enemy : Monobehaviour
{
    // Our data object 
    public EnemyData enemyData;
}

You can now simply assign the EnemyData object by dragging the object from the Databrain editor to the Enemy script inspector field.

Using the dropdown attribute

DataObject Property Drawer

By using the dropdown attribute, you can use additional features such as quickly unassigning an object or quickly creating a new DataObject of type EnemyData directly from the field. To do this, simply add the DropdownObjectAttribute to your EnemyData field like this:

We can now access the data directly from the data object like this:

Get initial data directly from the DataLibrary object

It is also possible to get the data object directly from the DataLibrary object. In this case you simply have to reference the DataLibrary object as follow:

You can now access the data object like this:

API

Please head over to the API section of the DataLibrary to see more methods for accessing data from the DataLibrary object.

Custom GUI

Last updated