# 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.

<div align="left"><figure><img src="/files/bKlCzY08JQExHrxqeD8M" alt=""><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="/files/R0ZEUGN2RbDs65NQmy9V" alt=""><figcaption></figcaption></figure></div>

3. 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.

<div align="left"><figure><img src="/files/pq7TPF9I8NyEGy8tejfi" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
You can organize your components by simply creating a new class file and deriving from  SceneComponent. Like in following example:
{% endhint %}

```csharp
public class PlayerComponents : SceneComponent {}
```

<div align="left"><figure><img src="/files/rLx6D1KZ4BQtqCfl12B5" alt=""><figcaption></figcaption></figure></div>

## Access component in nodes

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

```csharp
public SceneComponent playerObject;
```

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

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

In your node execute method you can then access the assigned component using <mark style="background-color:orange;">GetReference\<T>(NodeData node)</mark>

```csharp
// 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);
}   
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://giantgrey.gitbook.io/databrain/add-ons/logic/scene-components.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
