Page 1 of 1

Adding Actors to db at runtime?

Posted: Sat Jul 02, 2022 9:45 am
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());

Re: Adding Actors to db at runtime?

Posted: Sat Jul 02, 2022 12:12 pm
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.