Conversation added at runtime not found in database

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Ders
Posts: 18
Joined: Thu Mar 10, 2016 3:53 am

Conversation added at runtime not found in database

Post 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.
User avatar
Tony Li
Posts: 20766
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation added at runtime not found in database

Post 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.
Ders
Posts: 18
Joined: Thu Mar 10, 2016 3:53 am

Re: Conversation added at runtime not found in database

Post 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?
User avatar
Tony Li
Posts: 20766
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation added at runtime not found in database

Post by Tony Li »

Adding and removing databases is not a particularly heavy process. You can do it throughout the game.
Ders
Posts: 18
Joined: Thu Mar 10, 2016 3:53 am

Re: Conversation added at runtime not found in database

Post by Ders »

Good to know! I changed it to create the Database like you said and it works perfectly! Thanks again
User avatar
Tony Li
Posts: 20766
Joined: Thu Jul 18, 2013 1:27 pm

Re: Conversation added at runtime not found in database

Post by Tony Li »

Happy to help!
Post Reply