Selecting Dialog Option With Number Keys

Announcements, support questions, and discussion for the Dialogue System.
streethamster
Posts: 13
Joined: Wed Aug 19, 2020 6:14 pm

Selecting Dialog Option With Number Keys

Post by streethamster »

Hi, I've seen people ask this question at least two times on the forum but I couldn't understand the solutions.

What I have currently: I can pick dialogue options but I disabled the mouse cursor in favor of choosing dialogue options with the number keys.

Where do I go from here in a general sense? I checked off the Autonumber options in Standard UI Menu Panel as you advised another poster, but how do I actually get it working? Am I adding buttons that connect to specific dialogue choices? Thank you!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selecting Dialog Option With Number Keys

Post by Tony Li »

Hi,

I think there are two parts to the answer.

First, when you write your conversation, make sure the dialogue options are assigned to the Player actor. They'll be colored blue in the Dialogue Editor:

dialogueOptions.png
dialogueOptions.png (12.7 KiB) Viewed 2050 times

If a dialogue entry node links only to blue nodes, then it will show a response menu. If it links to any gray nodes, it will follow the gray node instead of showing the blue nodes in a response menu.

Second, when a node only links to blue nodes, it will show each of the blue nodes' text in a response button. How it shows the buttons depends on the dialogue UI. You can assign different dialogue UIs to the Dialogue Manager GameObject, including your own custom dialogue UIs. By default, the Basic Standard Dialogue UI prefab is assigned to the Dialogue Manager prefab. Some dialogue UIs, such as the Basic Standard Dialogue UI, instantiate copies of a template button at runtime. In this case, it creates copies of this button and then sets them up with autonumbering if the Autonumber options are enabled. Other dialogue UIs, such as the Wheel Dialogue UI used in DemoScene1, have a list of predefined buttons. In this case, the menu uses these predefined buttons and applies autonumbering to them.
streethamster
Posts: 13
Joined: Wed Aug 19, 2020 6:14 pm

Re: Selecting Dialog Option With Number Keys

Post by streethamster »

Thank you for your reply! So I have my dialogue set up like you have it in the screenshot. After that I'm a little confused, unfortunately. I understand what you're saying but I'm not sure how I can apply it.

I have the Basic Standard Dialogue UI Prefab in the Dialogue System Controller, I have three dialogue options, I have Autonumber options enabled, how can I connect the responses to the number keys? I looked at the Wheel Dialogue UI but wasn't able to see how I could use the predefined buttons to activate specific dialogue choices.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selecting Dialog Option With Number Keys

Post by Tony Li »

What's currently happening in your UI?

Here's an example:

1. I opened DemoScene1, assigned the Basic Standard Dialogue UI to the Dialogue Manager, and ticked the menu panel's Autonumber feature:

autonumber1.png
autonumber1.png (76.3 KiB) Viewed 2046 times

2. Then I added a couple of extra responses to the example database and tested it out:

autonumber2.png
autonumber2.png (258.67 KiB) Viewed 2046 times

You can see that it added "1", "2", and "3" to the button labels. Internally it mapped hotkeys so you can press the 1, 2, or 3 keys to select the button.
streethamster
Posts: 13
Joined: Wed Aug 19, 2020 6:14 pm

Re: Selecting Dialog Option With Number Keys

Post by streethamster »

It worked! You're the best, thank you. The thing I was doing wrong was that I added the Basic Standard Dialogue UI to the Dialogue Manager but it wasn't parented to the canvas.

I have two related UI questions, if you have time:

1 - Now I see the dialogue UI on the game screen when it's not in playmode, anyway to disable/hide the UI when not in playmode?

2 - Is there a way to dynamically resize the dialogue UI based on word count or would have to be scripted?
Attachments
Annotation 2020-08-20 130635.png
Annotation 2020-08-20 130635.png (349.62 KiB) Viewed 2042 times
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selecting Dialog Option With Number Keys

Post by Tony Li »

streethamster wrote: Thu Aug 20, 2020 6:19 pm1 - Now I see the dialogue UI on the game screen when it's not in playmode, anyway to disable/hide the UI when not in playmode?
Yes. Deactivate the Alert Panel and Dialogue Panel GameObjects. The dialogue UI will automatically reactivate them when needed.
streethamster wrote: Thu Aug 20, 2020 6:19 pm2 - Is there a way to dynamically resize the dialogue UI based on word count or would have to be scripted?
The subtitle panels automatically resize. The response menu panel doesn't, but you can set it up with a Content Size Fitter so it resizes to fit its content. For more info, see Making UI elements fit the size of their content. RayWenderlich.com also has a very good Unity UI Tutorial Series.
streethamster
Posts: 13
Joined: Wed Aug 19, 2020 6:14 pm

Re: Selecting Dialog Option With Number Keys

Post by streethamster »

Thank you, Tony, I'm having a great time working with DS thanks to your help.

I was looking through Conversation.cs trying to figure out how to play an animation on a character when a specific dialogue entry is picked. This is using Animator controller.

Ideally, I would like to add one script to a character, then call different character animations based on specific dialogue entries.

I was hoping I could script it with the dialogue entry #ID: If (dialogueEntry_9 = true) {anim.Play("Dance");} or something like that, but I couldn't zero in on it through the documentation.

Working within the GUI is fine too if coding it isn't possible. Thank you again, Tony.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selecting Dialog Option With Number Keys

Post by Tony Li »

Hi,

The usual way is to use sequences (tutorial).

For example, set dialogue entry 9's Sequence field to: AnimatorPlayWait(Dance)

If you want to code it instead, add a script to the character that has an OnConversationLine method. In that method, you can make sure that this character is the one who's speaking, and check its dialogue entry info.
streethamster
Posts: 13
Joined: Wed Aug 19, 2020 6:14 pm

Re: Selecting Dialog Option With Number Keys

Post by streethamster »

Thank you, Tony. I was able to get the first method working through the GUI but I'm trying the scripting method now and I'm lost.

I have this line from the documentation: public void OnConversationLine(Subtitle subtitle) {
Debug.Log(string.Format("{0}: {1}", subtitle.speakerInfo.transform.name, subtitle.formattedText.text));
}

How can I retrieve the dialogue entry number as well as the name of the character?
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Selecting Dialog Option With Number Keys

Post by Tony Li »

Hi,

I think the first method is the way to go, but if you need to go the scripting route, check subtitle.speakerInfo.Name and subtitle.dialogueEntry.id. API reference for subtitle: Subtitle
Post Reply