I wrote C# code to change the dialogue text for a specific dialogue entry of a particular conversation, when player takes a specific action.
From what I can tell, my coding works: When player clicks a certain response button, various options disappear and, therefore, the initial "dialogue text" is no longer valid, since it refers to options that are no longer available. This is why I wrote code to change this dialogue entry, after player chooses this key option.
When I check the actual Dialogue Entry Node (while game still running), the text has clearly been updated in the database; but, in the Conversation window itself, the dialogue entry does not change! It doesn't match what is clearly entered in the database. So seems like I must be missing some final step in this process Even if I start and restart the Conversation, that Dialogue Entry is STILL not updated in the Conversation window. I usually have to stop and restart the game, in order the see the changes reflected in the Conversation window!
Any suggestions?? Is this intended functioning? Is it possible to do what I want to do??
UPDATING DIALOGUE ENTRIES
Re: UPDATING DIALOGUE ENTRIES
Hi,
Your dialogue database is an asset in your project. The Dialogue System can read dialogue text directly from the dialogue database asset, or it can instantiate a copy in memory and read from that. If you tick the Dialogue Manager GameObject's Other Settings > Instantiate Database, it will instantiate a memory copy. In either case, the correct way to access the database at runtime is to use the property DialogueManager.masterDatabase.
In general, it's usually best to think of the dialogue database as read-only at runtime. Otherwise, if you change the dialogue database asset's content at runtime, those changes will be permanent; they won't be undone when you exit play mode. However, if you tick Instantiate Database, you can change the content of DialogueManager.masterDatabase at runtime because you'll only be changing the in-memory copy.
That said, the usual way to control which options appear in response menus is to set the Conditions fields of the response dialogue node entries. (See: Conversation Conditions Tutorial.)
Another way to change text at runtime is to put the text in a Dialogue System variable (e.g., using DialogueLua.SetVariable() in C#), or write a C# method that returns a string and register that C# method with Lua. If you put text in a variable, you can use a [var=variable] markup tag in the dialogue entry's Dialogue Text. If you register a C# method with Lua, you can use a [lua(code)] markup tag.
Your dialogue database is an asset in your project. The Dialogue System can read dialogue text directly from the dialogue database asset, or it can instantiate a copy in memory and read from that. If you tick the Dialogue Manager GameObject's Other Settings > Instantiate Database, it will instantiate a memory copy. In either case, the correct way to access the database at runtime is to use the property DialogueManager.masterDatabase.
In general, it's usually best to think of the dialogue database as read-only at runtime. Otherwise, if you change the dialogue database asset's content at runtime, those changes will be permanent; they won't be undone when you exit play mode. However, if you tick Instantiate Database, you can change the content of DialogueManager.masterDatabase at runtime because you'll only be changing the in-memory copy.
That said, the usual way to control which options appear in response menus is to set the Conditions fields of the response dialogue node entries. (See: Conversation Conditions Tutorial.)
Another way to change text at runtime is to put the text in a Dialogue System variable (e.g., using DialogueLua.SetVariable() in C#), or write a C# method that returns a string and register that C# method with Lua. If you put text in a variable, you can use a [var=variable] markup tag in the dialogue entry's Dialogue Text. If you register a C# method with Lua, you can use a [lua(code)] markup tag.
Re: UPDATING DIALOGUE ENTRIES
Thanks for quick turnaround, Tony! Guess I will have to go through info you provided carefully, to decide the best way to proceed.
But one of your replies makes me wonder if you understand what I am trying to do, since I am NOT trying to control what options are displayed. That part is working fine. I have a Lua bool that I use as a condition to decide whether or not to display those options. So my only issue now is that the dialogue text itself still refers to these old options, even after they are no longer there.
Again, the dialogue text in the DB DOES get updated with my code, for the given dialogue entry. And the updated text gets displayed on the next game restart. So guess I was hoping there was a way to simply "refresh" the Conversation window, so that it newly grabs subtitle/dialogue text.
Anyway, thanks again! Hopefully one of the options you provided will work for me! Unfortunately, don't think I am familiar with anything you are referring to, so assume it will take a while to get this all worked out! Take care!
But one of your replies makes me wonder if you understand what I am trying to do, since I am NOT trying to control what options are displayed. That part is working fine. I have a Lua bool that I use as a condition to decide whether or not to display those options. So my only issue now is that the dialogue text itself still refers to these old options, even after they are no longer there.
Again, the dialogue text in the DB DOES get updated with my code, for the given dialogue entry. And the updated text gets displayed on the next game restart. So guess I was hoping there was a way to simply "refresh" the Conversation window, so that it newly grabs subtitle/dialogue text.
Anyway, thanks again! Hopefully one of the options you provided will work for me! Unfortunately, don't think I am familiar with anything you are referring to, so assume it will take a while to get this all worked out! Take care!
Re: UPDATING DIALOGUE ENTRIES
Oh, by "conversation window" do you mean the runtime dialogue UI that the player sees?
If so, I was completely mistaken. I thought you were talking about the Dialogue Editor window's Conversations section.
If you're referring to the runtime dialogue UI, you'll need to handle that with your own code.
If you're referring to the Dialogue Editor's Conversations section, if you've ticked Instantiate Database then it should show the current changes if you double-click on the Dialogue Manager's Initial Database field. At runtime, the Initial Database field will point to the instantiated in-memory copy of the database.
If so, I was completely mistaken. I thought you were talking about the Dialogue Editor window's Conversations section.
If you're referring to the runtime dialogue UI, you'll need to handle that with your own code.
If you're referring to the Dialogue Editor's Conversations section, if you've ticked Instantiate Database then it should show the current changes if you double-click on the Dialogue Manager's Initial Database field. At runtime, the Initial Database field will point to the instantiated in-memory copy of the database.
Re: UPDATING DIALOGUE ENTRIES
Sorry, Tony! Wasn't sure about the terminology! But, yes, referring to UI panel that pops up, when game is running, after triggering a Conversation, that players see and interact with, while playing the game.
When player makes a final decision, after going down a few branches, he is returned to the main dialogue entry.
And, so far, my code and Editor setup works to disable two of the four response buttons that would normally be displayed on that dialogue entry, since those options would no longer be available. And my code also works to change the dialogue text (subtitle)that is displayed in that dialogue entry going forward. But, as reported, so far, game has to be restarted, before player sees the updated text in that dialogue entry.
After reviewing your reply, sounds like you're saying that I have to handle things with code, if I am referring to the runtime Dialogue UI (think that's the term you used - can't see your reply, while editing). If so, then that's why I am posting: How do I do that? How do I refresh the UI panel to display the updated dialogue text, so game doesn't have to be restarted?
When player makes a final decision, after going down a few branches, he is returned to the main dialogue entry.
And, so far, my code and Editor setup works to disable two of the four response buttons that would normally be displayed on that dialogue entry, since those options would no longer be available. And my code also works to change the dialogue text (subtitle)that is displayed in that dialogue entry going forward. But, as reported, so far, game has to be restarted, before player sees the updated text in that dialogue entry.
After reviewing your reply, sounds like you're saying that I have to handle things with code, if I am referring to the runtime Dialogue UI (think that's the term you used - can't see your reply, while editing). If so, then that's why I am posting: How do I do that? How do I refresh the UI panel to display the updated dialogue text, so game doesn't have to be restarted?
Re: UPDATING DIALOGUE ENTRIES
If the game needs to be restarted, it suggests to me that you're changing the dialogue database asset instead of the in-memory copy. Are you changing it through DialogueManager.masterDatabase?
Can you post some diagrams or annotated screenshots to illustrate what you want to happen? I'm still not sure I understand, but I have a suspicion that you might be able to accomplish it without much if any code.
I've finished work for the night, but I'll check back in the morning.
Can you post some diagrams or annotated screenshots to illustrate what you want to happen? I'm still not sure I understand, but I have a suspicion that you might be able to accomplish it without much if any code.
I've finished work for the night, but I'll check back in the morning.
Re: UPDATING DIALOGUE ENTRIES
Tony,
In earlier phase of the project, I had to figure out how to use code to change dialogue entries. For that, I dragged & dropped the actual DialogueDatabase file into a public reference to "DialogueDatabase" in the Unity Editor. So sounds like that means I AM using the "dialogue database asset"?? Didn't have any issues with that solution, so never thought there might be some other way to do this.
I see lots of scripting info on your site, but not always clear how to use all of that info for a given purpose. But, after reading your reply, instead of using the public reference I created earlier, I created a new private DialogueDatabase variable and used "DialogueManager.masterDatabase" to initialize it. After updating my code to use this new database reference, looks like everything is finally working as intended, after hours of trying!
Now the response buttons are being disabled (for the options that are no longer available)AND the dialogue text is immediately updated in the Dialogue UI, when the Conversation returns to the main DialogueEntry!
As usual, you have my endless gratitude, sir! Thanks so much! Looks like this is what you were trying to explain, in your first reply, but I didn't understand, until your last reply!
In earlier phase of the project, I had to figure out how to use code to change dialogue entries. For that, I dragged & dropped the actual DialogueDatabase file into a public reference to "DialogueDatabase" in the Unity Editor. So sounds like that means I AM using the "dialogue database asset"?? Didn't have any issues with that solution, so never thought there might be some other way to do this.
I see lots of scripting info on your site, but not always clear how to use all of that info for a given purpose. But, after reading your reply, instead of using the public reference I created earlier, I created a new private DialogueDatabase variable and used "DialogueManager.masterDatabase" to initialize it. After updating my code to use this new database reference, looks like everything is finally working as intended, after hours of trying!
Now the response buttons are being disabled (for the options that are no longer available)AND the dialogue text is immediately updated in the Dialogue UI, when the Conversation returns to the main DialogueEntry!
As usual, you have my endless gratitude, sir! Thanks so much! Looks like this is what you were trying to explain, in your first reply, but I didn't understand, until your last reply!
Re: UPDATING DIALOGUE ENTRIES
Happy to help! I'm glad you got it working the way you want. Thanks for your patience while we both got on the same page of understanding.