Adding Actions to your Character
Follow these instructions to enable actions for your Convai-powered characters.
Setting Up Action Configurations
Select the Convai NPC character from the hierarchy.
Scroll down to the ConvaiNPC script attached to your character.
Click the "Add Component" button.
Use the checkbox to add the action script to the NPC Actions.
Click "Apply Changes" to confirm.
Pre-defined Actions
Convai offers predefined actions for a quick start.
Click the "+" button to add a new action.
From the dropdown menu, select "Move To."
Enter the action name as "Move To" (the name doesn't have to match the action choice name).
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
Add any object into the scene—a sphere, a cube, a rock, etc.—that can be interacted with
Resize and place the object in your 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.
Add the "There" object in Objects list, so that we can use the Dynamic Move Target indicator.
Add the Dynamic Move Target Indicator and setup NavMesh agent to you NPC.
Setting Up NavMesh
To ensure your NPCs can navigate the scene:
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.
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.
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".
Test the Setup
Click "Play" to start the scene.
Ask the NPC, "Bring me the Box."
If setup properly, the NPC should walk upto the box and bring it to you
This feature is currently experimental and can misbehave. Feel free to try it out and leave us any feedback.
Adding Custom Actions to Your Unity NPC in Convai
Introduction
Make your NPC perform custom actions like dancing.
Action that Only Requires an Animation
Locate the dance animation file within our plugin.
Incorporate this animation into your NPC's actions.
Setting Up the Animator Controller
Open the Animator Controller from the Inspector window.
Drag and drop the dance animation onto the controller, creating a new node named "Dancing."
Adding custom Animation Action
Go to the Action Handler Script attached to your Convai NPC.
Add a new action named "Dancing."
In the Animation Name field, enter "Dancing" (it must exactly match the Animator Controller node name).
Leave the enum as "None."
Testing the Custom Action
Click "Play" to start the scene.
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
Grab a throw animation from Mixamo or anywhere you like.
Import it into Unity.
Setting Up the Animator Controller
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
Add the "Throw" enum to the script.
In the "Do Action" function, add a switch case for the throw action.
Define the "Throw()" function.
Adding the Throw Action
Add a new action named "Throw" and select the "Throw" enum.
Leave the animation name field empty.
Adding the Object (Rock) to the Convai Interactables Data script
Add any rock prefab into the scene.
Add the rock to the Convai Interactable Data script.
Adding a location to Convai Interactables Data script
Add a stage/new location in the ground of the scene.
Add that new location game object in the Convai Interactable Data.
Testing the Complex Action
Click "Play" to start the scene.
Instruct the NPC, "Pick up the rock and throw it from the stage."
If everything is set up properly, the NPC should pick up the rock and throw it from the stage.
Last updated