# Simple Talking Cube

1. Create a new first person project.<br>

   <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FimmcuDzw7xDAMiFKDx1H%2Fimage.png?alt=media&#x26;token=f9e36961-8081-43b9-810f-b3eb09e19d14" alt="" width="563"><figcaption></figcaption></figure></div>
2. Enable the Convai plugin and add the API key as [mentioned here](https://docs.convai.com/api-docs/plugins-and-integrations/unreal-engine/guides-v2-under-development/download-and-setup#set-up-your-project).<br>
3. Create a new Actor blueprint that we will be using as the AI character.\
   \
   ![](https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FxNwl8SJhS9g5P2jSXwNa%2Fimage.png?alt=media\&token=8f4a3e7e-2082-4c1a-946a-a224b3c78093)![](https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FKjwP6gSuO8XISyAVg1ri%2Fimage.png?alt=media\&token=f98de758-a06f-4b77-8075-94cf40fc7961)
4. Open the created blueprint then search for and add the `Convai Chatbot` component in the components list. \
   \
   Note: if you do not find the component then ensure that you have properly installed and enabled the plugin by following the [Installation guide](https://docs.convai.com/api-docs/plugins-and-integrations/unreal-engine/guides-v2-under-development/download-and-setup#installing-the-plugin).<br>

   <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FgtrqIMXD78fBvUMab1eA%2Fimage.png?alt=media&#x26;token=f766e519-3e4d-444a-b974-b5a89f1c5fe9" alt="" width="563"><figcaption></figcaption></figure></div>
5. Select the created component and on the details panel, find the Character ID field and paste your character ID which you can get by creating a new character or using an existing one on the [Convai Playground](https://docs.convai.com/api-docs/plugins-and-integrations/unreal-engine/guides-v2-under-development/getting-started/broken-reference).<br>

   <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FBRykO5zVayRaAkrhNAXw%2Fimage.png?alt=media&#x26;token=bd146028-578e-4964-8f08-749b69f3c6be" alt="" width="563"><figcaption></figcaption></figure></div>
6. Add a box component so that you can see the blueprint when placed in the scene.<br>

   <div align="left" data-full-width="false"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fl47ATzG7ieuDnfwycY0w%2Fimage.png?alt=media&#x26;token=239a74c2-0e9f-4102-a31c-717ac0113f33" alt="" width="563"><figcaption></figcaption></figure></div>
7. Place the blueprint in the scene.<br>

   <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fm5eU6wVkPrBr2YUa4ycu%2Fimage.png?alt=media&#x26;token=725e1e75-fc1c-48bd-a801-fce02db97f85" alt="" width="563"><figcaption></figcaption></figure></div>
8. Open the player blueprint which by default in `First Person/Blueprints/BP_FirstPersonCharacter` for the first person template.<br>

   <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FDOg7Glf0SFG989cV7HQ8%2Fimage.png?alt=media&#x26;token=e4f6541a-e357-4f30-8e67-900cbd120747" alt="" width="563"><figcaption></figcaption></figure></div>
9. Search and add the `Convai Player` component in the components list.<br>

   <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FQCzw1UsEwHO2NWKp0Imd%2Fimage.png?alt=media&#x26;token=b7bb65e5-6483-4e5b-827c-82f78d785b29" alt="" width="563"><figcaption></figcaption></figure></div>
10. Add the following blueprint schematic to allow the player to talk to the AI character via the V key:

    1. Add a keyboard key event to be used as a push to talk button (i.e. the \`V\` key in this example).
    2. Use `Convai Get Looked At Character` to get the chatbot component of the character that is currently viewed by the player.
    3. Set `Radius` to a reasonable distance or zero if you want the player to be talk the character over an infinite distance.
    4. Set `Plane View` to true to only consider the plane axis (X & Y) and ignore the height axis (Z), this is made to prevent having to look directly at the pivot of the character, instead only looking in the direction of the character is sufficent.
    5. Use the `Start Talking` node from the `Convai Player` component initiates the talking session with the character, ensure you have enabled `Voice Response` to get the character to respond vocally.
    6. On the `Released` event, use the `Finish Talking` node on the `Convai Player` component to let the AI character know that we have finished talking and are now waiting for a response.<br>

    <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FbWbrVwBdvF2ZaiI58hPT%2Fimage.png?alt=media&#x26;token=3d62a42c-7278-4f05-b20a-4ddb29406208" alt="" width="563"><figcaption></figcaption></figure></div>
11. Hit play, approach the AI character and push T to talk through the microphone, the character should then respond after releasing the T key.<br>

    <div align="left"><figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F6GgLUbaY7DRt3ofe8wqP%2Fimage.png?alt=media&#x26;token=75d7d9c5-f8f7-4201-a334-fdf41de8a86d" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
If the character does not respond then make sure your microphone is set properly as the default microphone in the OS settings.
{% endhint %}

## Sending Text instead of Voice

Use the following `Send Text`  node instead if you want to text chat with the character instead of voice.&#x20;

Note, over here we use a hard coded string as input to the character, you will need to create the required UI to get the text input from the user and send it to the AI character.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FXD5WzLvI0dFU9CW7iHbl%2Fimage.png?alt=media&#x26;token=67a8854a-596e-4585-b67f-15cc0759e0b7" alt=""><figcaption></figcaption></figure>
