Page 1 of 1

Conversation added at runtime not found in database

Posted: Mon Jun 13, 2016 5:35 am
by Ders
I've been trying to get a system working to add conversations at runtime to the DialogueDatabase.
This has been working for a while but I found a bug last week in my code that made the Lua variables in the Database reset to their original state (which I don't want). At that time, before I fixed that, I had this code:

Code: Select all

public static void FinishEditingConversation(ref Conversation conversation) {
    PersistentDataManager.Record();
    DialogueManager.DatabaseManager.DefaultDatabase.conversations.Add(conversation);
    DialogueManager.Instance.ResetDatabase(DatabaseResetOptions.KeepAllLoaded);
    PersistentDataManager.Apply();
}
This piece of code added the custom conversation to the database and this worked well, except for the Lua reset. Fixing the lua problem requried me to remove the ResetDatabase() line. I assumed that DatabaseResetOptions.KeelAllLoaded would keep that Lua data loaded as well, but apparently it doesn't.
So, at this time the Lua data stays the same when I add a custom conversation and the conversation shows up in the editor window when I look at that while playing the game, but when I try to talk to an NPC with this specific dialogue I get a warning
Conversation "custom_conversation_name" not found in database
What can I do to make this work? I'm not sure how I have to add the conversation without the Lua variables resetting.

Re: Conversation added at runtime not found in database

Posted: Mon Jun 13, 2016 9:46 am
by Tony Li
Hi,

Try this:

Code: Select all

public static void FinishEditingConversation(ref Conversation conversation) {
    var database = ScriptableObject.CreateInstance<DialogueDatabase>();
    database.conversations.Add(conversation);
    DialogueManager.AddDatabase(database);
} 
The solution is to add a database, not an individual conversation, using DialogueManager.AddDatabase(). This does extra work required to set up the runtime environment. If you only need to add one conversation, create a database containing that one conversation. Use RemoveDatabase() to remove the database if/when you're finished with it.

ResetDatabase() resets the active runtime environment, which includes resetting all variables. If KeepAllLoaded is specified, it keeps all currently-added databases. Otherwise it removes all but the Initial Database assigned to the Dialogue Manager. When the Dialogue System removes a database, it removes all variables defined in that database from the active runtime environment.

Re: Conversation added at runtime not found in database

Posted: Mon Jun 13, 2016 11:10 am
by Ders
Thanks for the help.
This way would be good if I add the custom conversations I need all at the same time so they could be in one Database.
What if I'm adding/removing conversation throughout the game? Would it be ok to just make a database per conversation? Or would this be bad for performance and such?

Re: Conversation added at runtime not found in database

Posted: Mon Jun 13, 2016 11:21 am
by Tony Li
Adding and removing databases is not a particularly heavy process. You can do it throughout the game.

Re: Conversation added at runtime not found in database

Posted: Tue Jun 14, 2016 4:07 am
by Ders
Good to know! I changed it to create the Database like you said and it works perfectly! Thanks again

Re: Conversation added at runtime not found in database

Posted: Tue Jun 14, 2016 8:47 am
by Tony Li
Happy to help!