For the complete documentation index, see llms.txt. This page is also available as Markdown.

Adding Actions to your Character

Follow the retained legacy Unity action workflow for existing projects and find the current Convai Unity SDK character actions guide for migration.

This page preserves the legacy Unity action workflow for projects that still use the older Convai integration.

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.

Unity Inspector with the Add Component control for the selected character
  1. Use the checkbox to add the action script to the NPC Actions.

  2. Click "Apply Changes" to confirm.

Legacy NPC Actions setup with the action script selected

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

Legacy action configuration dropdown with Move To selected
  1. Enter the action name as "Move To" (the name doesn't have to match the action choice name).

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

An interactable object placed in the Unity scene

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.

Legacy Convai Interactables Data component with character and object lists
Convai Interactables Setup

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.

    NavMeshAgent settings on the legacy Convai character

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

Dynamic Move Target Indicator positioned in the Unity scene

Test the Setup

  1. Click "Play" to start the scene.

  2. Ask the NPC, "Bring me the Box."

  3. If setup properly, the NPC should walk upto the box and bring it to you

Adding Custom Actions to Your Unity NPC in Convai

Create an animation action

Make your NPC perform custom actions like dancing.

Action that Only Requires an Animation

  1. Locate the dance animation file within our plugin.

    Dance animation asset selected in the Unity Project window
  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."

    Animator Controller with a Dancing animation state

Adding custom Animation Action

  1. Go to the Action Handler Script attached to your Convai NPC.

  2. Add a new action named "Dancing."

  3. In the Animation Name field, enter "Dancing" (it must exactly match the Animator Controller node name).

  4. Leave the enum as "None."

Legacy action handler configured with a Dancing action

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

Define the throwing action

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

Animation Requirement

  1. Grab a throw animation from Mixamo 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 Handler Script Setup

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

    Legacy action handler source with a Throw enum entry
  2. In the "Do Action" function, add a switch case for the throw action.

    Legacy Do Action switch with a Throw case
  3. Define the "Throw()" function.

    Legacy action handler source defining the Throw function

Adding the Throw Action

  1. Add a new action named "Throw" and select the "Throw" enum.

  2. Leave the animation name field empty.

    Legacy action configuration with the Throw action selected

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.

    Stage location added to the legacy interactable objects list

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.


Last updated

Was this helpful?