Enter response number in TMP Input Field

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
G00se
Posts: 4
Joined: Mon Mar 10, 2025 6:26 am

Enter response number in TMP Input Field

Post by G00se »

Hi,

Very impressed with the Dialogue System! There is, however, something that I just can't get my head around. I'm trying to create a sort of text adventure. The Dialogue System is used for every dialogue in the game, but also for navigating through menus. Here is the problem: I would like the player to enter one of the response options in a Text Mesh Pro Input Field and press the Enter key to confirm his choice. So the player will only use his keyboard. No mouse, no controller, only his keyboard.
I have enabled the Autonumber option in my Response Menu Panel, and the response options are now nicely autonumbered. Now, I don't want the game to automatically 'play', for example, option 1 when the player presses 1 on his keyboard (number hotkeys or numpad). Instead, he should enter that number in the Text Mesh Pro Input Field and press enter. Only then should his choice be processed.
I've created a manager class script that handles that input field. Is there specfic code that I can add, or are there parts of the Dialogue System scripts I need to alter in order to make this work?

Second question: Can I disable mouse and controller input specifically for the Dialogue System? Maybe, somewhere in the future, I may want to re-enable those via some sort of options menu, but for now I only require keyboard input from the player.

Thanks!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Enter response number in TMP Input Field

Post by Tony Li »

Hi,
G00se wrote: Mon Mar 10, 2025 6:41 am...I would like the player to enter one of the response options in a Text Mesh Pro Input Field and press the Enter key to confirm his choice. So the player will only use his keyboard. No mouse, no controller, only his keyboard.
I have enabled the Autonumber option in my Response Menu Panel, and the response options are now nicely autonumbered. Now, I don't want the game to automatically 'play', for example, option 1 when the player presses 1 on his keyboard (number hotkeys or numpad). Instead, he should enter that number in the Text Mesh Pro Input Field and press enter. Only then should his choice be processed.
I've created a manager class script that handles that input field. Is there specfic code that I can add, or are there parts of the Dialogue System scripts I need to alter in order to make this work?
When the player presses Enter, get the integer value from the input field. Then call the dialogue UI's OnClick(Response) method with the corresponding response from DialogueManager.currentConversationState.pcResponses[]:

Code: Select all

void SelectResponseByNumber(int number)
{
    var response = DialogueManager.currentConversationState.pcResponses[number - 1];
    DialogueManager.standardDialogueUI.OnClick(response);
}
(Note: For clarity, the code above doesn't do any value checking. In practice, you'll want to make sure the number the player enters is valid.)
G00se wrote: Mon Mar 10, 2025 6:41 amSecond question: Can I disable mouse and controller input specifically for the Dialogue System? Maybe, somewhere in the future, I may want to re-enable those via some sort of options menu, but for now I only require keyboard input from the player.
Inspect the Dialogue Manager GameObject's Input Device Manager component. Set Input Device to Keyboard. Clear all of the "*** Codes to Check" lists (Joystick Key Codes To Check through Key Codes To Check). UNtick Detect Mouse Control and Control Cursor State.
G00se
Posts: 4
Joined: Mon Mar 10, 2025 6:26 am

Re: Enter response number in TMP Input Field

Post by G00se »

Thanks! That really helped me!

Another question: there are some cases where the player has to type in words, instead of just the numbers from the response menu, (player name, a specific word to further the dialogue, etc.). Is there anything special I should do or think about when using this system? For example, if in the dialogue an npc asks for the player name (like in the beginning of so many games), normally I would use something like the TextInput sequence in the dialogue entry, right? I mean, if I read the tutorials and docs correctly.
Can I use the TMP Input field I've been using for the 'main' response input for this?

EDIT: I should mention that I have a separate GameObject that holds the Dialogue Manager (I have separate GameObjects for every manager script). The TMP Input Field is not a child of that GameObject.
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Enter response number in TMP Input Field

Post by Tony Li »

Hi,

Sure. The TextInput() sequencer command is just provided as a convenience. You can, for example, read the player's name from any source and then use DialogueManager.ChangeActorName() to change the actor's name.
G00se
Posts: 4
Joined: Mon Mar 10, 2025 6:26 am

Re: Enter response number in TMP Input Field

Post by G00se »

Ah, that makes sense. Changing the player name worked when I use that code outside of a dialogue (basically before any dialogue is started), like:

Code: Select all

public void GameStateChangedCallback(GameState state)
        {
            switch (state)
            {
                case GameState.STORY:
                //...
                    PixelCrushers.DialogueSystem.DialogueManager.ChangeActorName("Player", "TestName");
                    PixelCrushers.DialogueSystem.DialogueManager.StartConversation("TESTING");
                    break;
            }
        }


Now, just one last question: in most cases the response menu is enough to go through the dialogue. But what if I want the player to type a word/string? So for example, the npc asks to give him a day of the week. How would I set this up, so that no response options are given to the player, but he has to manually type in his answer and the dialogue waits for this input? Or: how can I link a specific dialogue entry to the TMP input field, and then use the answer given by the player in the rest of the dialogue?
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Enter response number in TMP Input Field

Post by Tony Li »

Hi,

Use TextInput(), similarly to how it's described in How To: Read Input From Player During Conversations.

See the Terminal conversation used in DemoScene1 for an example.
G00se
Posts: 4
Joined: Mon Mar 10, 2025 6:26 am

Re: Enter response number in TMP Input Field

Post by G00se »

Tony Li wrote: Mon Mar 10, 2025 1:27 pm Hi,

Use TextInput(), similarly to how it's described in How To: Read Input From Player During Conversations.

See the Terminal conversation used in DemoScene1 for an example.
Thank you! The demo helped. I got it working by using a second TMP Input Field that holds a StandardUIInputField script component (the 'main' input field does not have this script attached to it) and is a child of the DialogueUI GameObject.

Thanks for your help!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Enter response number in TMP Input Field

Post by Tony Li »

Glad to help!
Post Reply