Scene Components

Using Logic, you can reference scene-specific components or game objects.

Define components

  1. Go to the Components type in the Databrain editor and create a new data object.

  1. Select the newly created data object. You can now define the component type by clicking on the dropdown button.

  1. Now, when assigning a graph to a logic controller component in the scene, the inspector shows you all available scene components. You can assign the references here.

You can organize your components by simply creating a new class file and deriving from SceneComponent. Like in following example:

public class PlayerComponents : SceneComponent {}

Access component in nodes

To access a component in your custom node, simply create a reference of type SceneComponent like this:

public SceneComponent playerObject;

You can use the DataObjectDropdown attribute to specify the scene component type:

[DataObjectDropdown(true, sceneComponentType: typeof(GameObject))]
public SceneComponent playerObject;

In your node execute method you can then access the assigned component using GetReference<T>(NodeData node)

// adding true to include all derived types of SceneComponent
[DataObjectDropdown(true, sceneComponentType: typeof(GameObject))]
public SceneComponent playerObject;

public override void ExecuteNode()
{
    var _playerObject = playerObject.GetReference<GameObject>(this);
}   

Last updated