Adding Actors to db at runtime?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
darkmalice
Posts: 4
Joined: Fri Jul 01, 2022 10:24 am

Adding Actors to db at runtime?

Post by darkmalice »

I've a list of generated NPCs at runtime I'd like to add as actors, permanently changing the asset db. However, I can't see what I'm missing to make this work. I have the Dialogue system Controller setting for 'instantiate database' unchecked. Do I perhaps needs to create a new db, merge, and then somehow write it to the asset?

Code: Select all

Actor a = new Actor()
            {
                Name = c.GetCitizenName(),
                IsPlayer = false,
                Description = "A citizen who enjoys " + c.GetCitizenPreference().ToString()
            };
DialogueManager.databaseManager.MasterDatabase.actors.Add(a);
I've also tried to just alter the existing actor's name, but that doesn't seem to stick either.

Code: Select all

DialogueLua.SetActorField("NPC Actor", "Name", c.GetCitizenName());
User avatar
Tony Li
Posts: 22148
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding Actors to db at runtime?

Post by Tony Li »

Hi,

When the Dialogue System starts up at runtime, it creates a masterDatabase in memory from the dialogue database that's assigned to the Dialogue Manager GameObject's Initial Database field.

To add actors at runtime, create a new database and then call DialogueManager.AddDatabase() to add it to the masterDatabase. Please see: How To: Create Dialogue Database At Runtime

Make sure to use ID numbers that are different from the Initial Database.
Post Reply