How to instantiate npcs in unity

Original Discord Post by akster213 | 2024-08-27 14:49:01

Hey everyone, I’m new to Convai as I was previously using Inworld but will switch due to their licensing changes. I wanted to see if I could get some help on recreating my application using Convai. I am working on a research project that has to do with NPC interaction, and the application involves many subsequent faster-paced interactions. So we programmatically instantiate and destroy the NPC to move on to the next in line. What controls does Convai offer in terms of NPC instantiation? Every demo I’ve seen has had the character already present, but I was wondering if there was a way to easily just instantiate and destroy my Convai characters. If there is additional work needed on manually managing session ids or anything like that, also please let me know. I am working in Unity btw

Reply by akster213 | 2024-08-27 15:10:15

Or would it be as simple as SetActive true and false?

Reply by k3kalinix | 2024-08-27 15:15:04

Hello <@443251260288794624>,

Welcome to Convai Community!

Reply by k3kalinix | 2024-08-27 15:15:12

You can Instantiate and destroy your Character Prefab as you wish.

Reply by k3kalinix | 2024-08-27 15:16:32

If you make it Enable / Disable. You need to re-initalize the character’s Session ID to -1.

Reply by k3kalinix | 2024-08-27 15:17:03

Of course, if you want to start it as a separate session.

Reply by akster213 | 2024-08-27 15:17:26

When I tried setting it active and inactive more than once, it stopped responding after the second time, is that why?

Reply by akster213 | 2024-08-27 15:17:49

Would there be a way to do it as the same session?

Reply by k3kalinix | 2024-08-27 15:17:58

Are there any console errors?

Replying to akster213’s Message

Reply by akster213 | 2024-08-27 15:17:49
Would there be a way to do it as the same session?

Reply by k3kalinix | 2024-08-27 15:18:47

Ok then you can use enable/disable instead of instantiate/destroy

Reply by k3kalinix | 2024-08-27 15:19:04

Let me see the console logs

Reply by akster213 | 2024-08-27 15:20:19

After enabling and disabling the first time, when it is enabled again it immediately says he stopped listening

Images:

Reply by k3kalinix | 2024-08-27 15:21:16

I see. I’ll tag my teammate,
He can guide you.

<@679221735458996224>

Reply by akster213 | 2024-08-27 15:21:43

Ok, thanks

Reply by starboy_24 | 2024-08-27 15:59:06

I will check it out and get to you <@443251260288794624> , might be due to some variable or improper event handling.

Reply by starboy_24 | 2024-08-28 08:02:38

Hey <@443251260288794624> I am able to correctly implement the disable/enable functionality. And character is talking after I enable again. Are you sure you are doing it well?

Reply by starboy_24 | 2024-08-28 08:02:49

We can get on a call if you want

Reply by akster213 | 2024-08-28 18:45:55

Hey, thanks for checking it out but I think I figured it out, wasn’t doing it right the first time

Reply by k3kalinix | 2024-08-29 07:38:32

Awesome :+1:t2:

This conversation happened on the Convai Discord Server, so this post will be closed.