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:
Now, in our Monobehaviour script, we can add the following reference:
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
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:
Please note that we have to add an additional reference to our Data Library object and also have to pass in the name of the data library as parameter to the DataObjectDropdown attribute.
We can now access the data directly from the data object like this:
Please note that before we can access the data at runtime, we have to make sure the data is initialized. This can be done by registering a method to the initialization callback via RegisterInitializationCallback.
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.
pageCustom GUILast updated