Manual invoke a narrative trigger in Unity using script

Original Discord Post by petroslouca | 2024-08-31 00:26:52

Hello,
could you please provide a simple example in the case that there are more than one NPC’s in a Unity3D scene, on how to invoke a specific narrative trigger included in the narrative design of one of the NPCs, using a script that is attached to a new/empty game object?

Thank you!

Reply by petroslouca | 2024-08-31 00:27:17

Manual invoke a narrative trigger in Unity using script

Reply by k3kalinix | 2024-08-31 00:27:40

Hello <@606256062613684224> :wave:t2:

Reply by k3kalinix | 2024-08-31 00:27:58

Which version of Convai are you using?

Reply by petroslouca | 2024-08-31 00:30:19

I downloaded it from asset store and installed it a couple of weeks ago.

Reply by k3kalinix | 2024-08-31 00:31:07

Is this a new project?

Reply by petroslouca | 2024-08-31 00:33:10

I have been already working on a VR project using XRI toolkit 2.5.2

Reply by k3kalinix | 2024-08-31 00:33:19

Okey

Reply by k3kalinix | 2024-08-31 00:38:02

Add,

  • NarrativeDesignManager
  • NarrativeDesignTrigger components to your NPC.

There are two ways,
First we can call a trigger on ConvaiNPC or create a new script.
If you use the ConvaiNpc Method, it will affect all NPCs.

In ConvaiNPC or New Script, add this code to the Start method.

if (TryGetComponent(out NarrativeDesignTrigger narrativeDesignTrigger))
  {
    narrativeDesignTrigger.InvokeSelectedTrigger();
  }

Reply by petroslouca | 2024-08-31 00:39:02

You mean inside a publicly accesible function?

Reply by k3kalinix | 2024-08-31 00:39:38

What do you mean

Reply by petroslouca | 2024-08-31 00:39:49

I prefer a new script so as not modify any code in the original scripts.

Reply by petroslouca | 2024-08-31 00:41:38

I will better continue tomorrow, too many hours of work! Thank you for your immediate response.

Reply by k3kalinix | 2024-08-31 00:41:54

You are welcome :blush:

Reply by petroslouca | 2024-08-31 18:14:12

Hello! Could we discuss the solution please?

Reply by k3kalinix | 2024-08-31 18:28:00

Yes

Reply by petroslouca | 2024-08-31 23:10:56

So, create a new Gameobject with a script like the following attached to it:

using Convai.Scripts.Narrative_Design;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Convai.Scripts.Utils;
using Convai.Scripts;

public class NarrativeDesignManualTrigger : MonoBehaviour
{
[Header(“AVATAR MEDIEVAL OUTLANDER DATA”)]
[Tooltip(“CONVai NPC”)]
public ConvaiNPC convaiNPC_MedievalOutlander;
//[Tooltip(“CONVai NPC GO for accessing the collider’s radius”)]
//public GameObject convaiNPC_MedievalOutlander_GO;

// Start is called before the first frame update
void Start()
{
    convaiNPC_MedievalOutlander = GetComponent<ConvaiNPC>();
}

public void WelcomeTrigger()
{
    ConvaiNPCManager.Instance.SetActiveConvaiNPC(convaiNPC_MedievalOutlander);

    if (convaiNPC_MedievalOutlander.TryGetComponent(out NarrativeDesignTrigger narrativeDesignTrigger))
    {            narrativeDesignTrigger.InvokeSelectedTrigger();
    }
}

}

Is this approach right?

Reply by petroslouca | 2024-08-31 23:17:57

It is important to have the avatar talking even if not directly having the user’s crosshair on it, as I understand that narrative trigger can be used to have the avatar acting/talking on a user’s event, e.g. approaching a specific game object.

Reply by petroslouca | 2024-08-31 23:29:05

Could you provide additional reousrces to the documentation (Adding Narrative Design to your Character | Documentation) for a more detailed information about invoking triggers from a script? An online video (YouTube) specifically on this aspect, would be really helpful!

Embedded Content:
Adding Narrative Design to your Character | API Docs
Follow this guide to incorporate Narrative Design into your Convai-powered characters. Follow this step-by-step tutorial, open your project, and let’s begin!
Link: Adding Narrative Design to your Character | Documentation

Replying to petroslouca’s Message

Reply by petroslouca | 2024-08-31 23:10:56
So, create a new Gameobject with a script like the following attached to it:

using Convai.Scripts.Narrative_Design;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Convai.Scripts.Utils;
using Convai.Scripts;

public class NarrativeDesignManualTrigger : MonoBehaviour
{
[Header(“AVATAR MEDIEVAL OUTLANDER DATA”)]
[Tooltip(“CONVai NPC”)]
public ConvaiNPC convaiNPC_MedievalOutlander;
//[Tooltip(“CONVai NPC GO for accessing the collider’s radius”)]
//public GameObject convaiNPC_MedievalOutlander_GO;

// Start is called before the first frame update
void Start()
{
    convaiNPC_MedievalOutlander = GetComponent<ConvaiNPC>();
}

public void WelcomeTrigger()
{
    ConvaiNPCManager.Instance.SetActiveConvaiNPC(convaiNPC_MedievalOutlander);

    if (convaiNPC_MedievalOutlander.TryGetComponent(out NarrativeDesignTrigger narrativeDesignTrigger))
    {            narrativeDesignTrigger.InvokeSelectedTrigger();
    }
}

}

Is this approach right?

Reply by k3kalinix | 2024-09-01 00:32:35

No, this is wrong