# Adding Actions to your Character

## Setting Up Action Configurations

1. Select the Convai NPC character from the hierarchy.
2. Scroll down to the ConvaiNPC script attached to your character.
3. Click the "Add Component" button.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fb06DsiOiHzNt8yLiXhVe%2Fimage.png?alt=media&#x26;token=f511980d-6b14-45b8-a339-b0c51d1c3f32" alt="" width="438"><figcaption></figcaption></figure>

4. Use the checkbox to add the action script to the NPC Actions.
5. Click "Apply Changes" to confirm.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FfDgdUhcTl2aIFHfrvInd%2Fimage.png?alt=media&#x26;token=88ed20a6-f14d-429e-b6be-5a00a360f6e5" alt="" width="563"><figcaption></figcaption></figure>

## Pre-defined Actions

Convai offers predefined actions for a quick start.

1. Click the "+" button to add a new action.
2. From the dropdown menu, select "Move To."

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FqeGC7yKbbge4o5HuRLzF%2Fimage.png?alt=media&#x26;token=f95b2865-ea80-4e90-b185-ec289c8227a1" alt=""><figcaption></figcaption></figure>

3. Enter the action name as "Move To" (the name doesn't have to match the action choice name).
4. Leave the Animation Name field empty for now.

Repeat these steps to add more actions like "Pickup" and "Drop" etc.

### Adding an Object in the Scene

1. Add any object into the scene—a sphere, a cube, a rock, etc.—that can be interacted with
2. Resize and place the object in your scene.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FfhljP7dm60FsoHDMbCbu%2Fimage.png?alt=media&#x26;token=806554cc-9851-4eb1-97e5-f0f23ef0cdfb" alt=""><figcaption></figcaption></figure>

### Adding the Convai Interactables Data Script

* Create an empty GameObject and name it "Convai Interactables."
* Attach the Convai Interactables Data script to this GameObject.
* Add characters and objects to the script by clicking the "+" button and attaching the corresponding GameObjects.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FeozeOhx4vjvOAoHA6ydg%2Fimage.png?alt=media&#x26;token=a19125de-bccd-451f-85de-b310736ccb03" alt=""><figcaption><p>Convai Interactables Setup</p></figcaption></figure>

* Add the "There" object in Objects list, so that we can use the Dynamic Move Target indicator.<br>

  <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F4sKwUATtSeYDQ2zuCbvv%2Fimage.png?alt=media&#x26;token=7841f472-ec46-49f2-9087-93d5f266355a" alt=""><figcaption></figcaption></figure>
* Add the [Dynamic Move Target Indicator](#adding-a-dynamic-move-target-indicator) and setup [NavMesh agent](#setting-up-navmesh) to you NPC.

### Setting Up NavMesh

To ensure your NPCs can navigate the scene:

1. **Bake a NavMesh** for your scene if you haven't already:
   * Go to **Window > AI > Navigation**.
   * In the **Navigation** window, under the **Bake** tab, adjust the settings as needed.
   * Click **"Bake"** to generate the NavMesh.
2. Ensure that the NPC character has a **NavMeshAgent** component:

   * If not already attached, click **"Add Component"** and search for **NavMeshAgent**.
   * Adjust the **Agent Radius, Speed,** and other parameters according to your NPC's requirements.

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FBkCZTRp7by9bCs0mDAo6%2Fimage.png?alt=media&#x26;token=056817c4-dc1c-49cc-9cb0-ebda17ff67f9" alt=""><figcaption></figcaption></figure>

### Adding a Dynamic Move Target Indicator

To visually indicate where your NPC will move:

* Create a new empty GameObject in the scene and name it accordingly or use the pre-made prefab named **Dynamic Move Target Indicator.**
* Link this **Move Target Indicator** to your NPC's action script so it updates dynamically when you point the cursor to the ground and ask the NPC to move to "There".

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FISOT45TZnSaq6QVxdAvn%2Fimage.png?alt=media&#x26;token=5af4dea9-c89b-49e4-b226-06f4d7f80864" alt=""><figcaption></figcaption></figure>

### Test the Setup

1. Click "Play" to start the scene.
2. Ask the NPC, "Bring me the Box."&#x20;
3. If setup properly, the NPC should walk upto the box and bring it to you

{% hint style="warning" %}
This feature is currently experimental and can misbehave. Feel free to try it out and leave us any feedback.
{% endhint %}

## Adding Custom Actions to Your Unity NPC in Convai

### Introduction

Make your NPC perform custom actions like dancing.

### Action that Only Requires an Animation

1. Locate the dance animation file within our plugin.

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FcV6kdXXF9MBgQhd3Qs9E%2Fimage.png?alt=media&#x26;token=73e6cffa-4185-4424-b3b4-914e1078e51f" alt=""><figcaption></figcaption></figure>
2. Incorporate this animation into your NPC's actions.

### Setting Up the Animator Controller

1. Open the Animator Controller from the Inspector window.
2. Drag and drop the dance animation onto the controller, creating a new node named "Dancing."

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FZhDi7oDCUWqNW9EBO4ra%2Fimage.png?alt=media&#x26;token=f02bfe87-d7df-4931-8b9b-9815a03a90c2" alt=""><figcaption></figcaption></figure>

### Adding custom Animation Action

1. Go to the Action Handler Script attached to your Convai NPC.
2. Add a new action named "Dancing."&#x20;
3. In the Animation Name field, enter "Dancing" (it must exactly match the Animator Controller node name).
4. Leave the enum as "None."

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FHC7yf3x78rEu3THtdAhh%2Fimage.png?alt=media&#x26;token=32912565-538d-496f-ba04-9c24ee37b400" alt=""><figcaption></figcaption></figure>

### Testing the Custom Action

1. Click "Play" to start the scene.
2. Instruct the NPC, "Show me a dance move," and the NPC should start dancing.

## Creating Complex Custom Actions in Unity with Convai: Throwing a Rock

### Introduction

Adding advanced custom actions, such as a throw action, to your NPC.

### Animation Requirement

1. Grab a [throw animation from Mixamo](https://www.mixamo.com/#/?page=1\&query=throw) or anywhere you like.
2. Import it into Unity.

### Setting Up the Animator Controller

1. Drag and drop the throw animation onto the controller, creating a new node named "Throwing." (Follow steps in [#action-that-only-requires-an-animation](#action-that-only-requires-an-animation "mention"))

### Action Handler Script Setup

1. Add the "Throw" enum to the script.

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FdNNjyI4ZVIAvAyZAFfJ4%2Fimage.png?alt=media&#x26;token=45926fa9-7e05-49ee-b2c5-f501b8c367f1" alt=""><figcaption></figcaption></figure>
2. In the "Do Action" function, add a switch case for the throw action.&#x20;

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FBayuBcvaR2yDf8wMmGiB%2Fimage.png?alt=media&#x26;token=d186fb27-f4c7-4374-8b17-988579829c1b" alt=""><figcaption></figcaption></figure>
3. Define the "Throw()" function.&#x20;

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F4Cz4i2y6R1pKHsf50Oiy%2Fimage.png?alt=media&#x26;token=29f8862f-b09f-4dfb-8260-1deab56a8e52" alt=""><figcaption></figcaption></figure>

### Adding the Throw Action

1. Add a new action named "Throw" and select the "Throw" enum.&#x20;
2. Leave the animation name field empty.&#x20;

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FiyNDJKCtVq7N6nyI76jH%2Fimage.png?alt=media&#x26;token=37c69fc0-f416-4e63-899c-02de2efcb824" alt=""><figcaption></figcaption></figure>

### Adding the Object (Rock) to the Convai Interactables Data script

1. Add any rock prefab into the scene.
2. Add the rock to the Convai Interactable Data script.

### Adding a location to Convai Interactables Data script

1. Add a stage/new location in the ground of the scene.
2. Add that new location game object in the Convai Interactable Data.

   <figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fx410GNfL2FwSLk728tpt%2Fimage.png?alt=media&#x26;token=6f8aa815-d1e2-45e1-8b82-3400da01656b" alt=""><figcaption></figcaption></figure>

### Testing the Complex Action

1. Click "Play" to start the scene.
2. Instruct the NPC, "Pick up the rock and throw it from the stage."
3. If everything is set up properly, the NPC should pick up the rock and throw it from the stage.&#x20;

***


---

# 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://docs.convai.com/api-docs/plugins-and-integrations/unity-plugin/adding-actions-to-your-character.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.
