Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Unity Plugin Utilities - Enhance development with Convai's tools and resources.
Session ID Management - Manage unique session IDs for Convai Unity integration.
In a typical application integrating with the Convai API, maintaining a consistent session ID across different sessions is crucial for providing a seamless user experience. This documentation outlines the best practices for storing and retrieving session IDs using Unity's PlayerPrefs
, including detailed steps and example scripts.
A session ID uniquely identifies a session between the client and the Convai server. Storing the session ID locally ensures that the same session ID is used across different sessions, which helps in maintaining context and continuity in interactions.
When initializing a session, if a session ID is not available locally, it should be fetched from the server and then stored locally for future use. Here's how you can achieve this:
Fetch and Store Session ID: When initializing a session, check if a session ID is stored locally. If not, fetch a new session ID from the server and store it using PlayerPrefs
.
When initializing your application, retrieve the stored session ID to ensure continuity in user interactions.
The following example class demonstrates how to manage session IDs using PlayerPrefs
in a Unity project:
Initialize Session: Call InitializeSessionIDAsync
to check if a session ID is stored. If not, fetch and store it.
Store Session ID: Use PlayerPrefs.SetString(characterID, sessionID)
to store the session ID locally.
Retrieve Session ID: Use PlayerPrefs.GetString(characterID, string.Empty)
to retrieve the stored session ID.
Use Session ID: Pass the session ID to your Convai API calls to maintain session continuity.
Error Handling: Ensure proper error handling when fetching and storing session IDs.
Security: Consider encrypting sensitive information stored in PlayerPrefs
.
Performance: Use asynchronous methods to avoid blocking the main thread when fetching session IDs.
In this guide, we learn about character emotion coming from server
Convai Character emit character emotions when they interact with the player and these emotions help in making the character more human-like, we are starting to implement a system which you as a developer can use to make your game more interactive using the character emotions.
Whenever the character responds to the user, we send back a list of emotions to the SDK, which look something like this
For v0 of this system, we will only be sending the emotions, in future we will apply the facial expressions corresponding to each emotion which will make the character more interactive.
All the information that Convai SDK needs from the player to work properly
This is a scriptable object which is made automatically after you hit play in the editor with Convai SDK installed and in a Scene where Convai Base Scene Essentials Prefab is present
Default Player Name
You can provide a default name of your players.
Player Name
Current name of your player, out of the box if you use our settings panel, we keep it updated automatically, if you are using some custom logic, it will be your responsibility to keep it updated, as our transcript UI use this name to show it in UI
Speaker ID
Speaker ID for the player. Please note that Speaker ID is directly linked with your API key, so for each API key there should be a unique speaker ID associated with it. We handle the creation of the Speaker ID when it's not found in the Player Prefs if the Boolean is set to true.
Create Speaker ID If Not Found
This Boolean lets the SDK if it should create a unique Speaker ID for that Player Name if it is not found in the Player Prefs.
It just makes the Player Name and Speaker ID fields empty.
Copies the data into system buffer so you can paste it anywhere for debugging purpose
Load: Loads the Player Name and associated Speaker ID from the player Prefs
Save: Saves the Player Name and associated Speaker ID from the player Prefs
Delete: Deletes the Player Name and associated Speaker ID from the player Prefs
Convai provides a pre-made component which you can add to any GameObject
to make the PlayerDataContainer
work out of the box.
Choose an existing GameObject or create a new GameObject
in the scene and add the ConvaiPlayerDataHandler
component to your chosen GameObject
and it should start working
You can also create the required Scriptable Object by going to Assets > Convai > Resources
and right clicking in the project panel and navigating to Create > Convai > Player Data
and name it ConvaiPlayerDataSO
Make sure you name the created Scriptable Object exactly ConvaiPlayerDataSO
as our system looks for this exact name
Learn how to enable character retain conversation history across multiple sessions
Long-Term Memory (LTM) enables the persistent storage of conversational history with NPCs, allowing players to seamlessly continue interactions from where they previously left off, even across multiple sessions. This feature significantly enhances the realism of NPCs, aligning with our goal of creating more immersive and lifelike characters within your game.
Prerequisite: Have a project with Convai SDK version 3.1.0 or higher. If you don't have it, check this documentation
Select your Convai Character
Add the Long-Term Memory Component onto your character
Make sure that Long Term Memory is enabled for that character
Long Term Memory should now be working for your character.
This component will enable or disable LTM right from the unity editor
Toggling Long Term Memory
1) Click the button provided in the component
2) It will take some time to update, and after that the new status of the LTM should be visible in the inspector.
Since enabling or disabling Long-Term Memory (LTM) for a character is a global action that impacts all players interacting with that character, we strongly recommend against toggling the LTM status at runtime. This functionality should be managed exclusively by developers or designers through the editor to ensure consistent gameplay experiences.
Grpc.Core.RpcException: Status(StatusCode=InvalidArgument, Detail="Cannot find speaker with id: 99fbef96-5ecb-11ef-93ce-42010a7be011.")
If you encounter this error, ensure that the SpeakerID was created using the same API key currently in use. If you're uncertain about the API key used, you can reset the SpeakerID and PlayerName by accessing the ConvaiPlayerDataSO
file located in Assets > Convai > Resources
, allowing you to start the process anew.
Convai UI Prefabs - Utilize ready-to-use UI elements for Convai integration.
We provide several UI options to display character and user's transcript out of the box that players can use with the Convai Plugin. You can use and customize these prefabs.
The ConvaiNPC and ConvaiGRPCAPI scripts look for GameObjects with Convai Chat UI Handler as a component, and send any transcripts to the script so that it can be displayed on screen.
Prefab Name: Convai Transcript Canvas - Chat
Both the user's and the character's transcripts are displayed one after other in a scrollable chat box.
Prefab Name: Convai Transcript Canvas - Subtitle
The user and character transcripts are displayed in the bottom like subtitles.
Prefab Name: Convai Transcript Canvas - QA
The user's transcript is displayed in the top where as the character's transcript is displayed in the bottom.
Prefab Name: Convai Transcript Canvas - Mobile Subtitle
Identical to #subtitle UI. Includes a button that can be pressed and held for the user to speak. Ideal for portrait orientation of screen.
Prefab Name: Convai Transcript Canvas - Mobile QA
Prefab Name: Convai Transcript Canvas - Mobile Chat
Settings Panel - Customize settings using Convai's Unity plugin utilities.
Settings Panel consists of two main sections.
Audio Settings
Interface Settings
The Microphone Settings section is primarily for troubleshooting and testing the microphone when using the Convai plugin.
In the Input section, you can view the microphones connected to your computer and select the desired one.
In the Test Input field, you can record your voice using the selected microphone in the Input section. After clicking Stop, you can listen to the recorded voice and observe the sound levels.
The first setting that greets us here is the Appearance setting.
In the Appearance section, you can switch between Transcript UI designs.
There are three Transcript UI options:
ChatBox
QuestionAnswer
Subtitle
The second section in Interface Settings is the Display Name section. This section allows you to change how the user's name appears in the Transcript UI.
The last section in Interface Settings is the Notifications Checkmark.
Convai sometimes displays notifications on the screen to inform the user. If you want to disable these notifications, you can click the checkbox here. ( If the box is green, it's active. If empty, it's inactive )
For more information about notifications, you can refer to this link.
Notification System - Implement notifications with Convai Unity plugin utilities.
The Convai plugin comes with default notifications, totaling four. Here they are:
Appears when you press the talk button but there is no active NPC nearby.
Appears if you release the talk button in less than 0.5 seconds.
Appears when the recorded audio input level is below the threshold.
Appears when there is no internet connection upon launching the application.
Adding your custom notification is straightforward.
Let's go through the steps to add a " CharacterStartedListening" notification as an example.
Open the script "Convai/Scripts/Notification System/Notification Type.cs." This script stores Notification Types as enums. Give a name to your desired Notification type and add it here.
Right-click on "Convai / Scripts / Notification System / Scriptable Objects" and select "Create > Convai > Notification System > Notification" then create a "Notification Scriptable Object".
Name the created Notification Scriptable Object. Click on it, and fill in the fields in the Inspector as desired.
Add the created Notification Scriptable Object to "Convai/Scripts/Notification System/Scriptable Objects" under "Convai Default Notification Group" (details of Notification Group here****).
Your Notification is now ready. The last step is to call this Notification from where you need it. For example, if you created the " CharacterStartedTalking " Notification, find the location where your character listens and write the code.
Replace the parameter with the NotificationType you created. (For our example, NotificationType.CharacterStartedListening)
Ensure that the Convai Notification System is present in your scene. (accessible from "Convai/Prefabs/ Notification System")
All steps are complete, and you're ready to test!🙂✅
This Scriptable Object stores information about a Notification
Notification Type
Notification Icon
Notification Title
Notification Message
To create a new Notification Scriptable Object, right-click anywhere in the Project Window and select "Create > Convai > Notification System > Notification"
This Scriptable Object stores Notification Scriptable Objects as groups. When a Notification is requested, it searches for the Notification using the specified Notification Group in the Convai Notification System prefab's Notification System Handler script.
You can create different Notification groups based on your needs. Note: If your referenced Notification Group does not have the Notification you want, that Notification won't be called.
The Convai Default Notification Group has four Notifications, but you can add more or create a new group with additional notifications.
Transcript UI System - Integrate transcript UI with Convai's Unity plugin.
The Dynamic UI system is a feature within the Convai Unity SDK that provides developers a robust system for in-game communication. This feature allows for displaying messages from characters and players and supports various UI components for chat, Q&A sessions, subtitles, and custom UI types. This document will guide you through the integration, usage, and creation of custom UI types of the Dynamic UI feature in your Unity project.
To interact with the chat system, you need to reference the ConvaiChatUIHandler
in your scripts. You can find the Transcript UI prefab in the Prefabs folder.
Here's an example of how to find and assign the handler:
Once you have a reference to the ConvaiChatUIHandler
, you can send messages using the following methods:
Sending Player Text
To send text as the player:
input
: The string containing the player's message.
To send text as a character:
characterName
: The name of the character sending the message.
currentResponseAudio.AudioTranscript
: The transcript of the audio response from the character, trimmed of any leading or trailing whitespace.
To create a custom UI type, follow these steps:
Create a new C# script in your Unity project and define your class to inherit from ChatUIBase
. For example:
Implement the abstract methods from ChatUIBase
. You must provide implementations for Initialize
, SendCharacterText
, and SendPlayerText
:
Add any additional functionality or customization options that your custom UI may require.
To use your custom UI class within the dictionaryConvaiChatUIHandler
, you need to add it to the GetUIAppearances
dictionary. This involves creating a prefab for your custom UI and assigning it in the ConvaiChatUIHandler
.
Here's an example of how to do this:
Create a prefab for your custom UI and add your CustomChatUI
component to it.
Assign the prefab to a public variable in the ConvaiChatUIHandler
script.
Modify the InitializeUIStrategies
method in the ConvaiChatUIHandler
script to include your custom UI type.
Ensure that your custom UI type is added to the UIType
enum:
By following these steps, you can integrate your custom UI type into the Dynamic Chatbox system and switch between different UI types at runtime.
Input Management - Efficiently handle input for Convai's Unity plugin integration.
Make sure that Active Input Handling in
"Project Settings > Player" is set to Both or Input System Package (New).
Our recommendation is Both. This way, you can use both the new and old input systems. Using the old input system can be faster when creating inputs for testing purposes.
Double click on the "Controls" asset in your project tab.