Pick response programmatically?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
onpocket
Posts: 13
Joined: Fri Feb 01, 2019 5:04 am

Pick response programmatically?

Post by onpocket »

Hi there! I've been working on a project in which i need to implement response selection programmatically, that is instead of calling the response picked by the user through the OnClick() method in AbstractDialogueUI.cs class (based in what i could understand of the dialogue system API references), i want to send it through a custom method. It would also be important to be able to check programmatically the number of possible responses available in each dialogue response entry of a single conversation, so that i could associate the custom methods to each one of the possible responses (this part is similar to some tell tale games https://cdn.thinglink.me/api/image/8296 ... aletowidth).

In summary, i want to adapt the dialogue system to my custom input system, instead of using Unity's default one.

Any suggestions? Which methods should i look into?
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Pick response programmatically?

Post by Tony Li »

If you only need to send a response programmatically, call the dialogue UI's OnClick(Response) method. For example:

Code: Select all

Responses[] currentResponses;
void OnConversationResponseMenu(Responses[] responses) 
{ 
    Debug.Log("Number of responses: " + responses.Length);
    currentResponses = responses; 
}
...
// Click the first response:
FindObjectOfType<AbstractDialogueUI>().OnClick(currentResponses[0]);
This uses the OnConversationResponseMenu message that's sent to the Dialogue Manager.

If you want to completely override how the UI works, make a subclass. The most targeted approach is to override StandardUIMenuPanel and replace your dialogue UI's StandardUIMenuPanel component with your subclass. Override the ShowResponses() and HideResponses() methods. This overrides the behavior when the Dialogue System uses a specific menu panel. In most projects, there's only one menu panel, so it's basically equivalent to the alternative below:

Alternatively, you can make a subclass of StandardDialogueUI and override its ShowResponses() and HideResponses() methods.


BTW, you can do the Telltale style input shown in your screenshot with the Dialogue System's standard dialogue UI. Here's how:
  • Set up response buttons A/B/X/Y, and assign them to the dialogue UI's StandardUIMenuPanel > Buttons list.
  • Set the Dialogue Manager's Input Settings > Response Timeout value. (You can also use the SetTimeout() sequencer command to change timeout values on the fly.)
  • Set the Dialogue Manager's Input Settings > Response Timeout Action to specify what to do if the timer runs out before the player has chosen a response.

Of course, if none of the solutions above fit your needs, you can write your dialogue UI completely from scratch. Simply implement the IDialogueUI interface, and assign your dialogue UI to the Dialogue Manager. As long as it implements IDialogueUI, the Dialogue System will happily work with it.
onpocket
Posts: 13
Joined: Fri Feb 01, 2019 5:04 am

Re: Pick response programmatically?

Post by onpocket »

That will solve my problem, thank you so much!
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Pick response programmatically?

Post by Tony Li »

Glad to help!
Post Reply