Setting Database By Code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
patxiku
Posts: 14
Joined: Tue Nov 07, 2017 6:46 am

Setting Database By Code

Post by patxiku »

Hi, I'm having a "nullreference exception" error while setting a database inside my script.
The database is correctly referenced and I use the "dialogueSystemController.AddDatabase()" method to set it.
Is this the proper way of doing this?
Thanks in advance.
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting Database By Code

Post by Tony Li »

Hi,

Can you use DialogueManager.AddDatabase(DialogueDatabase)?

For example, say you have a dialogue database asset named DB1 in a Resources folder. You can load it into the Dialogue System like this:

Code: Select all

using PixelCrushers.DialogueSystem;
...
var database = Resources.Load("DB1") as DialogueDatabase;
if (database != null) DialogueManager.AddDatabase(database);
There are some other examples on this forum of converting articy:draft and Chat Mapper files at runtime into databases and then adding them, as well as creating a database from scratch in code using the Template class. (To use the Template class, create an instance by calling Template.FromDefault(). Then use the Template methods such as CreateConversation to create a new conversation that you can add to the database.)

If you're still getting an error, would you please click on the error message in the Console window, press Ctrl+C to copy it to the clipboard, and then paste it into a reply? This will include the full stack trace that should help identify the issue.
patxiku
Posts: 14
Joined: Tue Nov 07, 2017 6:46 am

Re: Setting Database By Code

Post by patxiku »

Thank you!
Post Reply