Why are changes in the 'MasterDatabase' not persistent?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Dralks
Posts: 44
Joined: Mon May 24, 2021 6:19 pm

Why are changes in the 'MasterDatabase' not persistent?

Post by Dralks »

I'm adding some conversations at runtime, this is working totally fine when I manually assign the database:

Image

but when I try to use the master database directly through code, everything works fine code wise (I can see the conversation being added in the list of conversations to the correct database), but the conversation never makes it to the actual database and is lost somewhere:

Code: Select all

 private void Awake()
    {
        database = DialogueManager.MasterDatabase;
    }
shouldn't 'masterdatabase' update the assigned DialogueManager database?

Image
User avatar
Tony Li
Posts: 22133
Joined: Thu Jul 18, 2013 1:27 pm

Re: Why are changes in the 'MasterDatabase' not persistent?

Post by Tony Li »

Hi,

A few things may be happening:

1. The Dialogue Manager initializes itself in Awake. If your own script's Awake method runs first, DialogueManager.masterDatabase may not be ready yet. In general, Awake methods should only access their own script's data; they should not access properties, variables, or methods on other scripts (e.g., DialogueManager). If you need to access another script's properties, variables, or methods, do it in Start.

2. If the Dialogue Manager GameObject's Other Settings > Instantiate Database checkbox is ticked, the Dialogue System will instantiate an in-memory copy of the Initial Database. If you make changes to this at runtime in the Unity editor's play mode, it will not affect the original database asset file in your project.

3. DialogueManager.masterDatabase is a runtime database that holds all of the databases that have been loaded, including the Dialogue Manager's Initial Database and any other databases you've loaded through Extra Databases components or DialogueManager.AddDatabase().
Dralks
Posts: 44
Joined: Mon May 24, 2021 6:19 pm

Re: Why are changes in the 'MasterDatabase' not persistent?

Post by Dralks »

Hi Tony, thanks for answering!

1. I seem to be doing that correctly (and always do as you mentioned because of bad experiences with):

Code: Select all

    private void Start()
    {
        database = DialogueManager.masterDatabase;
        template = TemplateTools.LoadFromEditorPrefs();
    }
2. the box is unticked.

3. this got me confused, so is it possible to use masterdatabase to update the current dialogue manager database or do I need to reference it every time?


Just to clarify, this is a brand new project with a brand new asset, I bought it for my personal use, so everything should be pristine straight out of the box.
User avatar
Tony Li
Posts: 22133
Joined: Thu Jul 18, 2013 1:27 pm

Re: Why are changes in the 'MasterDatabase' not persistent?

Post by Tony Li »

I think I misunderstood what you want to do. To add conversations at runtime, create a new database and add it to the master database by using DialogueManager.AddDatabase(). See:

How To: Create Dialogue Database At Runtime
Dralks
Posts: 44
Joined: Mon May 24, 2021 6:19 pm

Re: Why are changes in the 'MasterDatabase' not persistent?

Post by Dralks »

I tried that exact same code yesterday with the same result, the actual database never seems to be updated even when everything in memory seems to be correct, I created my own static Helper to grab the assigned database from the scene and that seems to update the actual file with every change, so I will just stick to using this script when I need to set values, thank you for your time Tony!

Code: Select all

public class DialogueDatabaseHelper : MonoBehaviour
{
    public DialogueDatabase database;
    private static DialogueDatabaseHelper instance;

    private void Awake()
    {
        instance = this;
    }

    public static DialogueDatabaseHelper Instance()
    {
        return instance;
    }
}
User avatar
Tony Li
Posts: 22133
Joined: Thu Jul 18, 2013 1:27 pm

Re: Why are changes in the 'MasterDatabase' not persistent?

Post by Tony Li »

Sorry, I misunderstood again. I thought you were trying to create a new conversation at runtime, which would only exist in memory while playing. The link above (How To: Create Dialogue Database At Runtime) explains how to do that.

If you want to modify a dialogue database asset file -- such as in a custom editor script -- use the Template class to get valid IDs for new conversations and dialogue entries, and remember to call EditorUtility.SetDirty() on the database so Unity's Asset Database knows to write its cached changes to disk.
Post Reply