Saving data for runtime generated actors
Posted: Tue Sep 27, 2022 11:19 am
We are generating NPCs with corresponding dialogue actors at runtime. We're adding these actors to the database on generation (when the player first encounters a spawn point for a new NPC in the world):
We also assign some data to the actor's lua fields during generation and gameplay. For example, we set "HasMetPlayer" to true when the NPC has met the player for the first time.
When the game is saved and reloaded the save data is restored to the lua system properly. However, the actor data is lost when the actor is later added to the database using DialogueManager.AddDatabase during generation. As far as I can tell this is due to AddToTable called from AddChatMapperVariables because it is replacing the actor's fields table with the fields on the actor being added (empty/template).
I'm adding the actors to the database with AddDatabase so their lua data isn't lost in the future when Quest Engine calls AddDatabase to add generated dialogue for actors.
Is there any way to ensure the lua data is preserved when we generate the actor? I thought about getting the Actor table when OnApplyPersistentData is called but I couldn't figure out how to convert the actors in the Actor table to database actors.
Any direction on the best way to go about this is highly appreciated!
Code: Select all
actor = new Actor(npcActorTemplate)
{
Name = characterData.FullName,
id = DialogueManager.MasterDatabase.actors.Count
};
var database = CreateInstance<DialogueDatabase>();
database.actors.Add(actor);
DialogueManager.AddDatabase(database);
When the game is saved and reloaded the save data is restored to the lua system properly. However, the actor data is lost when the actor is later added to the database using DialogueManager.AddDatabase during generation. As far as I can tell this is due to AddToTable called from AddChatMapperVariables because it is replacing the actor's fields table with the fields on the actor being added (empty/template).
I'm adding the actors to the database with AddDatabase so their lua data isn't lost in the future when Quest Engine calls AddDatabase to add generated dialogue for actors.
Is there any way to ensure the lua data is preserved when we generate the actor? I thought about getting the Actor table when OnApplyPersistentData is called but I couldn't figure out how to convert the actors in the Actor table to database actors.
Any direction on the best way to go about this is highly appreciated!