Skip to content

Referencing RPGObjects from Unity code

Robin van Ee edited this page Jan 22, 2023 · 5 revisions

In code

The RPGObjectReference type is used to reference objects.

[SerializeField] private RPGObjectReference characterReference;

The GetObject() method can be used to retrieve the object from the reference. The first time this is called, the asset is loaded from disk and deserialized, but it's cached afterwards

IRPGObject character = characterReference.GetObject();

GetComponent can then be used to retrieve individual components

ExampleComponent component = character.GetComponent<ExampleComponent>();

Assigning the reference

In the Unity inspector, a string is required to reference the object.

image

This should be equal to the Object Reference ID that can be found for each object in the database editor: image

Clone this wiki locally