> For the complete documentation index, see [llms.txt](https://indie-4.gitbook.io/function-calling-for-unity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://indie-4.gitbook.io/function-calling-for-unity/subscribing-to-a-brain.md).

# Subscribing To A Brain

Once the Tool and Parameter attributes are set up, Subscribe and Unsubscribe to any Brain in your scene.

### 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&amp;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&amp;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...
}
```
