Unity New Input System support questions

Announcements, support questions, and discussion for the Dialogue System.
ProvencalG
Posts: 24
Joined: Fri Mar 13, 2020 1:30 pm

Unity New Input System support questions

Post by ProvencalG »

Hi.

I was happy to notice that the new input system was supported since the last update.
Still I am struggling with it.

I can't manage to use the new input system with the dialogue system. I defined the scripting symbol USE_NEW_INPUT. I created and defined my actions, control schemes and bindings in an Input Actions Asset.
But I'm lost when in the input manual you say "you must register them with the Input Device Manager before calling any of the InputDeviceManager input query functions". Giving this example:

Code: Select all

void Awake()
{
    controls = new MyControls();
}
void OnEnable()
{
    controls.Enable();
    InputDeviceManager.RegisterInputAction("Back", controls.Gameplay.Back); 
    InputDeviceManager.RegisterInputAction("Horizontal", controls.Gameplay.Horizontal);
}
void OnDisable()
{
    controls.Disable();
    InputDeviceManager.UnregisterInputAction("Back");
    InputDeviceManager.UnregisterInputAction("Horizontal");
}
I guess that "controls" should be defined above, "InputActionAsset controls;". I also guess that using "UnityEngine.InputSystem;" and "PixelCrushers.DialogueSystem" is mandatory.

What is "MyControls()" exactly?

Should I create a script that register inputs in a similar way? When should I enable and disable it? Multiple controls schemes are all registered at once that way? Is there a way to treat control schemes differently?

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

Re: Unity New Input System support questions

Post by Tony Li »

Hi!

The new Input System is still in preview. I'm sure Unity will provide better documentation and tutorials as it gets closer to release, as well as best practices for using it. I'll continue updating the Dialogue System's integration as the Input System develops.

When you edit an input actions asset, the Input Manager window has a checkbox to Generate C# Class. The Dialogue System's documentation example assumes that you've generated a C# class named MyControls.cs.

You should create a script that registers your own inputs in a similar way. If you're only concerned about Dialogue System-specific inputs, such as the "Cancel Conversation" input defined in the Dialogue Manager's Input Setting section, then you can enable it when a conversation starts and disable it when the conversation ends. You can use a Dialogue System Events component on the Dialogue Manager to enable/disable the script, or you can add OnConversationStart and OnConversationEnd methods to your script.
ProvencalG
Posts: 24
Joined: Fri Mar 13, 2020 1:30 pm

Re: Unity New Input System support questions

Post by ProvencalG »

Thanks! I did not think about that C# Class.

I wonder, can I use the Player Input component and create events that trigger Dialogue System functions ?
For example StopConversation() from DialogueSystemController.

Anyway, now I'm trying to use those inputs I registered to answer specific response choice. In my conversations I have 3 choices maximum in each dialogue node. So I want 3 different inputs to trigger the max 3 different dialogue answers. I have no idea how.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Unity New Input System support questions

Post by Tony Li »

Hi,
ProvencalG wrote: Tue Mar 17, 2020 3:27 pmI wonder, can I use the Player Input component and create events that trigger Dialogue System functions ?
For example StopConversation() from DialogueSystemController.
I haven't tested to be sure, but I think you can do that.
ProvencalG wrote: Tue Mar 17, 2020 3:27 pmAnyway, now I'm trying to use those inputs I registered to answer specific response choice. In my conversations I have 3 choices maximum in each dialogue node. So I want 3 different inputs to trigger the max 3 different dialogue answers. I have no idea how.
If you want to map them to the number keys 1, 2, 3, then just turn on the Standard UI Menu Panel's Autonumbering.

If you want to map them to different inputs:

1. Register each input using InputDeviceManager.RegisterInputAction, such as:

Code: Select all

InputDeviceManager.RegisterInputAction("Response1", controls.dialogue.response1);
2. Add all 3 response buttons to the Standard UI Menu Panel's Buttons list.

3. Then add a UI Button Key Trigger to response button 1, and set the button name to "Response1". Do similarly for buttons 2 & 3.
ProvencalG
Posts: 24
Joined: Fri Mar 13, 2020 1:30 pm

Re: Unity New Input System support questions

Post by ProvencalG »

Hi,
So I tried that method and I don't know what I'm missing but no input I registered shows up in the Buttons list.Image

Do I need to register them using a specific name "Response1" etc? I tried that and it still does not show up.
Maybe I don't register my inputs properly. Image
Because I would expect them to show up in one of the InputDeviceManager lists in the inspector if it was registered.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Unity New Input System support questions

Post by Tony Li »

Hi,

Assign Button 1, Button 2, and Button 3 to the StandardUIMenuPanel's Design-Time Buttons > Buttons > Element 0, Element 1, and Element 2.

Add a UIButtonKeyTrigger component to each of the buttons. If you want to map the "1 key" input to Button 1, set the UIButtonKeyTrigger's Button Name field to "1 key".
ProvencalG
Posts: 24
Joined: Fri Mar 13, 2020 1:30 pm

Re: Unity New Input System support questions

Post by ProvencalG »

Hi,

So I tried and it does not trigger responses.
For exemple my button 1 UiButtonKeyTrigger is set up like this:
Image

My inputs work. And I think they are registered (my only guess is a debug.log at the end or the RegisterInputAction commands).
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Unity New Input System support questions

Post by Tony Li »

Hi,

Here's an example scene:

DS_NewInputSystemExample_2020-03-26.unitypackage

I copied DemoScene1 and made as few changes as possible -- just setting up new Input System hotkeys for the first two response buttons (mapped to '1' and '2'). I didn't set up input for player movement, so the player can't move around. The conversation starts immediately.

I've also fixed a small bug since the 2.2.5 release. When the new Input System support is enabled, UIButtonKeyTrigger doesn't like the Key dropdown to be "None". This patch fixes it:

DS_InputDeviceManager_Patch_2020-03-26.unitypackage

If your scene doesn't work after importing the patch and checking against the example scene, please check the Console for any errors or warnings.
ProvencalG
Posts: 24
Joined: Fri Mar 13, 2020 1:30 pm

Re: Unity New Input System support questions

Post by ProvencalG »

Yes it works!
In your demo and in my project.

Thanks a lot for your support!

I have a few other issues:

It does not trigger the pressed sprite of the button. I can create a script for that but still I'm letting you know.

And I have a probably unrelated issue, well, it's linked to the new input system I believe: Image

It does not happen in your demo so I guess this is probably my fault.
ProvencalG
Posts: 24
Joined: Fri Mar 13, 2020 1:30 pm

Re: Unity New Input System support questions

Post by ProvencalG »

That might help you Image
Post Reply