# Adding Narrative Design to your Character

## Convai Playground

### Step 1: Select your Character in which you want to enable Narrative Design

{% hint style="info" %}
For this demo, we are using `Seraphine Whisperwind`, you can select whatever character you want to enable Narrative Design.
{% endhint %}

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FVdP9GA4YFoyzj25J57gY%2FScreenshot%202024-05-22%20114710.png?alt=media&#x26;token=4e3ae8cb-24a2-43a6-aea1-493eec6a43b8" alt=""><figcaption><p>Screenshot showing selection of character in <a href="#convai-playground">Convai Playground</a></p></figcaption></figure>

### Step 2: Open Narrative Design in Convai Playground

Select the Narrative Design option from the side panel and create your narrative design

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FWUsVhaveSrL4Bicq0rjl%2FScreenshot%202024-05-22%20115450.png?alt=media&#x26;token=60d16d33-b3bf-4649-b494-6f00e1f8f8e6" alt=""><figcaption><p>Screenshot showing Icon of Narrative Design</p></figcaption></figure>

{% hint style="info" %}
For more information how to create narrative design in the [Convai Playground](#convai-playground) please refer to the following YouTube video series
{% endhint %}

{% embed url="<https://www.youtube.com/playlist?list=PLn_7tCx0Chip2mfSbOkqJLevEbm3jDuNV>" %}
Video series showing how to create Narrative Design
{% endembed %}

For this sample we have created the following Narrative design

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F5tzquGELWBGHWJ43qoXz%2FScreenshot%202024-05-23%20123350.png?alt=media&#x26;token=232fcc89-7a66-48e1-a4cd-235c0845b9ab" alt=""><figcaption></figcaption></figure>

You are all set to bring your character from Convai Playground to Unity, let's hope over to Unity to continue the guide

## Unity Setup

### Step 1: Add the Narrative Design Manager Component

#### Using <mark style="color:green;">Add Components</mark> Button in Convai NPC (Recommended Way)

#### **1:** Select your Convai Character in the scene and look for ConvaiNPC component in the inspector panel. Click on <mark style="color:green;">**Add Components**</mark> button

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F4zBy2JF14bAWLIxA4VwQ%2FScreenshot%202024-05-22%20122312.png?alt=media&#x26;token=6407ad84-8bd0-4baa-9c44-46812559756d" alt=""><figcaption><p>Screenshot showing location of <mark style="color:green;">Add Components</mark> button in the Convai NPC inspector panel </p></figcaption></figure>

#### **2:** Select **Narrative Design Manager** checkbox and then click on <mark style="color:green;">Apply Changes</mark> button

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FFCZENWMKDxJenEm8o2EC%2FND%20Component%20Selected.png?alt=media&#x26;token=fd65decb-47d2-4608-b1db-6ac26280b8e3" alt=""><figcaption><p>Screenshot showing selection of Narrative design option in the Add Component Window</p></figcaption></figure>

#### Using Unity Inspector

#### **1:**  Select your Convai Character and find Add Component button in the inspector panel&#x20;

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FKk7vHnoMKaR6KLS5ZOwK%2FScreenshot%202024-05-22%20122424.png?alt=media&#x26;token=eb3d954f-8a02-4bd0-89c1-8afb50505781" alt=""><figcaption><p>Screenshot showing location of Add Component button in the inspector panel</p></figcaption></figure>

#### 2: Search for `Narrative Design Manager` in the search box and select it

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fhr1IvEHvkCGO8Yb0dCBa%2FND%20Component%20Selected.png?alt=media&#x26;token=ad8a5c2d-91ee-45e1-9e8e-462233bb0041" alt=""><figcaption><p>Screenshot showing which component to select from the search results</p></figcaption></figure>

### Step 2: Setup the Narrative Design Component

After adding the Narrative Design Component, you will be able to be the following component

{% hint style="danger" %}
This component system assumes that API key is setup correctly, so ensure that API key is setup correctly otherwise an error will be thrown.
{% endhint %}

{% hint style="info" %}
After adding, component will retrieve the sections for the character ID taken from the ConvaiNPC, please wait for some time depending upon your network speed
{% endhint %}

{% hint style="warning" %}
The following section events are for character used in demo, and you will see section events corresponding to your character in which Narrative Design is enabled.&#x20;
{% endhint %}

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FfPrIoRevibp7ye3af1AL%2FScreenshot%202024-05-22%20122537.png?alt=media&#x26;token=844b77bb-3c39-4d4b-a50b-88e4a1fb54f6" alt=""><figcaption><p>Screenshot showing a sample Narrative Design component</p></figcaption></figure>

### Getting to know the Narrative Design Component

Expanding the section event, you will see two unity events you can subscribe to, one is triggered when section starts, and another one is triggered when section ends

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F58ErHzz6smZH2mjw96Pd%2FScreenshot%202024-05-22%20143301.png?alt=media&#x26;token=449d222b-1bc4-4b76-a196-cabe0500b3a8" alt=""><figcaption><p>Screenshot showing various unity events user can subscribe to</p></figcaption></figure>

### Getting to know about Section Triggers

Section triggers are a way to directly invoke a section in narrative design and can be used to jump to a different section in your narrative design

#### Step 1: Select the game object you want to make a trigger, in this example we have selected a simple cube, but it's up to your imagination.

{% hint style="info" %}
Make sure that game object you have decided to be a trigger have a collider attach to it
{% endhint %}

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F54r8jK8GnnDwRsJ8or25%2FScreenshot%202024-05-22%20144701.png?alt=media&#x26;token=11f18709-6261-464f-a0b4-9f9ac6c75506" alt=""><figcaption><p>Screenshot showing a game object with a collider selected</p></figcaption></figure>

#### Step 2: Add Narrative design Trigger from Add Component menu by searching for it

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FORJZh5Z0MpUTwi6XDgwH%2FScreenshot%202024-05-22%20145128.png?alt=media&#x26;token=307764c7-3cdb-4553-a4e7-58e85d7a3ae1" alt=""><figcaption><p>Screenshot showing selection of Narrative Design Trigger</p></figcaption></figure>

#### Step 3: Make the collider a trigger.

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F3vLmpGnjDerqXnZUnTSI%2FScreenshot%202024-05-22%20145314.png?alt=media&#x26;token=618e67d1-c3a1-4615-b055-042848717980" alt=""><figcaption><p>Screenshot showing Box Collider becoming a trigger box</p></figcaption></figure>

#### Step 4: Assign your Convai NPC to Convai NPC field

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F6HVQ1IwrEnZWAtU8NOKk%2FScreenshot%202024-05-22%20145631.png?alt=media&#x26;token=f35d8e8a-2605-49c6-8b8d-86fdcb35f3de" alt=""><figcaption><p>Screenshot showing assigning of Convai NPC to trigger component</p></figcaption></figure>

Now you can select from the "Trigger" dropdown which trigger should be invoked when player enters this trigger box.&#x20;

We have added a way for you to manually invoke this trigger also, you can use `InvokeSelectedTrigger` function to invoke the trigger from any where

<figure><img src="https://413558230-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F6UGCfq75lseBK1dL5AUZ%2FScreenshot%202024-05-23%20123713.png?alt=media&#x26;token=c6a64b74-2cca-4b78-b518-b301d92d71ff" alt=""><figcaption><p>Screenshot showing ability to select your desired trigger</p></figcaption></figure>

### Invoke Trigger from any script

You can use this code block as a reference to invoke the trigger from anywhere

```csharp
if(convaiNPC.TryGetComponent(out NarrativeDesignTrigger narrativeDesignTrigger))
{
    //Optional message parameter if you want to send some message while invoking
    //the trigger 
    string message = "Player has collected enough resources";
    narrativeDesignTrigger.InvokeSelectedTrigger(message);
}
```
