# Subscribing To A Brain

### Create An Instance Of A Brain

A brain is a scriptable object, so create an instance of that scriptable object in your project folder.&#x20;

(<mark style="color:green;">Hint\*</mark> *there can be more than one instance of a brain in any given project* :smile:)

Right-click in the project folder, go to Create -> Indie -> Brain

<figure><img src="https://787156514-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGkty9KvhE5iPf6S1txxc%2Fuploads%2FxPTGSQ97hUfZmhOHjBn3%2Fimage.png?alt=media&#x26;token=0997c0a9-df65-4c67-8e98-cc941841fdab" alt=""><figcaption><p>Create an instance of the Brain scriptable object</p></figcaption></figure>

This should create the brain with a System Message, Message History, and Context.

(<mark style="color:green;">Hint\*</mark> *Add a system message to give the brain character and guidelines of how to interact with the player* :brain:)

<figure><img src="https://787156514-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGkty9KvhE5iPf6S1txxc%2Fuploads%2FNbaPCeqSXDiO6ckraZnF%2Fimage.png?alt=media&#x26;token=2ebfee7d-7182-474f-9286-288618446fb3" alt=""><figcaption></figcaption></figure>

### Reference A Brain

```csharp
public Brain brain;
```

### Subscribe

Subscribe this script to the brain to be analyzed for tools.

```csharp
private void OnEnable()
{
    brain?.RegisterScript(GetType(), this);
}
```

### Unsubscribe

Unsubscribe this script from the brain when the script no longer needs to be considered by the brain.

```csharp
private void OnDisable()
{
    brain?.UnRegisterScript(GetType());
}
```

### Full Example Code

```csharp
using UnityEngine;
using Indie.Attributes;

public class MyGameController : MonoBehaviour
{
    public Brain brain;
    
    private void OnEnable()
    {
        brain?.RegisterScript(GetType(), this);
    }
    
    private void OnDisable()
    {
        brain?.UnRegisterScript(GetType());
    }


    [Tool("MovePlayer", "Move the player to a specified position.")]
    [Parameter("position", "Position to move the player to.")] 
    public void MovePlayer(Vector3 position)
    {
        // Method implementation
    }

    // Other methods...
}
```


---

# 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://indie-4.gitbook.io/function-calling-for-unity/subscribing-to-a-brain.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.
