Calling Dialogue Navigation methods in code

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Calling Dialogue Navigation methods in code

Post by robloxillian »

I am using the dialogue system and Unity's new input management system in my game. Inputs from the keyboard and controller are captured by an input manager (I think the asset name is "input action"). I've noticed that the controller does not automatically navigate between UI elements via Unity's default navigation, so I found ways to force this navigation in my code based on inputs. I'm not sure if this is recommended practice when working with the dialogue system, but it seems to be working for most areas of my game so I would prefer to do something similar for the dialogue system inputs.

Firstly, is my understanding correct that this is necessary given that navigation through button/selectable elements doesn't happen from inputs like the D-pad? Secondly, if so, what methods can I call in my input handling to:

- Scroll through different options when presented in a conversation
- Select a highlighted option

I have already found ways to speed up conversations and advance non-option conversations using Continue().
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling Dialogue Navigation methods in code

Post by Tony Li »

Hi,

On the Dialogue Manager's Input Device Manager component, try ticking the Always Auto Focus checkbox.

Also make sure your scene has an EventSystem GameObject. Inspect the EventSystem. You may need to click a button to switch it to use the Input System package. On the EventSystem's InputSystemUIInputModule component, you will see that an InputActions asset is assigned, and the inputs from that actions are selected for field such as UI/Vertical and UI/Submit.

If navigation works with the left stick but not the d-pad, check which input action is assigned to the Vertical field. You may need to edit this input action and map the d-pad to it, or assign a different input action that reads from the d-pad.
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Re: Calling Dialogue Navigation methods in code

Post by robloxillian »

I'm able to re-assign the input actions for the different fields in the InputSystemUIInputModule, but nothing allows me to change the selected dialogue option using the controller or keyboard. I verified that some of these fields are being used, as when I tried changing a few of them, I lost the ability to click on any of the dialogue options.

I don't see a vertical field in the list of options. This is what shows up for me:



Should I need to disable the other InputAction component while the dialogue conversation is open in order for the event system to register inputs? I noticed that using the scroll wheel while in a conversation changes the hotbar selection and I'm wondering if other inputs are being "consumed" and therefore not processed by the EventSystem.
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling Dialogue Navigation methods in code

Post by Tony Li »

Hi,
robloxillian wrote: Fri Jun 10, 2022 4:03 pmI noticed that using the scroll wheel while in a conversation changes the hotbar selection and I'm wondering if other inputs are being "consumed" and therefore not processed by the EventSystem.
Maybe? What hotbar?

If you're using More Mountains' Inventory Engine, make sure to UNtick the Inventory Input Manager component's Input Only When Open checkbox, or enable navigation when opening the dialogue UI by using this C# code:

Code: Select all

UnityEngine.EventSystems.EventSystem.current.sendNavigationEvents = value;
If you don't want to write any code, add a DialogueSystemInventoryEngineMethods component to your dialogue UI, and configure the Dialogue Panel's OnOpen() UnityEvent to call DialogueSystemInventoryEngineMethods.SetEventSystemNavigationEvents with the checkbox ticked.

If you're not using Inventory Engine, keep an inspector view on the EventSystem GameObject. Make sure something is reported as "Selected" at the bottom. Unity UI can only navigate between UI buttons if one is selected (focused).

Or consider using Unity's built-in input manager for fewer headaches. :-)
robloxillian
Posts: 27
Joined: Mon Sep 13, 2021 6:55 pm

Re: Calling Dialogue Navigation methods in code

Post by robloxillian »

Thank you! I tried updating the input manager checkbox and adding that line of code and now the controller is working for dialogue options.
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling Dialogue Navigation methods in code

Post by Tony Li »

Great! Glad I could help.
Post Reply