Page 1 of 1

Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 9:35 am
by LostTrainDude
[Unity 2019.4.15f1 - DS v2.2.14 - AC v1.72.4 - Input System v1.1.0-preview.2]

Hi Tony,
I just found out this issue so I can't really track whether it started in a previous DS version or not.

To make everything more clear, consider that:
  • The game I'm working on is set up to cater for both direct control with a Gamepad and mouse input;
  • I'm using the new Unity Input System;
  • I'm using Adventure Creator.
  • I have 2 different ActionMaps; one for when I'm in a Conversation and one for when I'm in "play mode". I handle this switch on a custom script and so far everything worked just fine.
  • My Dialogue UI is much like a Telltale one: a "radial" Response Menu, with 4 possible answers bound to specific keys\buttons. I have set it up using all your guidelines, including registering input as described in the Input_Device_Manager_Manual.pdf.
I normally have an initial scene where I already have everything I need to carry on to other scenes. So, for instance, my Dialogue Manager is a singleton ("Allow Only One Instance", "Don't Destroy on Load" and "Preload Resources" are all ticked) and I try to have it instantiate the EventSystem so that I'm sure that I'm not setting it up wrong. So far, so good.

That said, when I want to test out specific scenes, I just manually place a Dialogue Manager instance in the scene and enter Play Mode.

Doing so I've noticed that when I run the game from a specific scene, everything works as intended. If I start from my initial scene then move to a specific one, the Dialogue System isn't responding to my Controller input anymore.

Looking at the EventSystem in both scenarios, I noticed that when I run the specific scene, it correctly selects the correct GameObject relatively to the gamepad button I press.

Image

So, if I hit the "Answer 2" key, "Selected" points to "Response Button 2". If I enter this scene starting from a different one, it stays on "Response Button 1" (and won't even trigger it, by the way).

Do you have any suggestions on where to look?

FWIW, the Dialogue Manager I'm using is a prefab and I should be always using the same setup everywhere.

Thanks a lot in advance, as always!

Re: Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 11:41 am
by Tony Li
Hi,

I'm guessing that the second Dialogue Manager is unregistering the Dialogue System from the new Input System before it disappears.

Let's say you start in scene A and then go to scene B. Both scenes have a Dialogue Manager. Both Dialogue Managers have a script similar to the example in Input_Device_Manager_Manual.pdf.

When scene A starts, its Dialogue Manager's script registers the Dialogue System with the Input System in OnEnable().

When scene B starts, its Dialogue Manager B will notice that there's already an existing Dialogue Manager A, so Dialogue Manager B will destroy itself. This will call the script's OnDisable() method, which will inadvertently unregister the Dialogue System from the Input System.

Try changing the script to something similar to this:

Code: Select all

protected static bool isRegistered = false;
private bool didIRegister = false;

void Awake()
{
     controls = new MyControls();
}

void OnEnable()
{
    if (!isRegistered)
    {
        isRegistered = true;
        didIRegister = true;
        controls.Enable();
        InputDeviceManager.RegisterInputAction("Back", controls.Gameplay.Back);
        InputDeviceManager.RegisterInputAction("Vertical", controls.Gameplay.Vertical);
    }
}

void OnDisable()
{
    if (didIRegister)
    {
        isRegistered = false;
        didIRegister = false;
        controls.Disable();
        InputDeviceManager.UnregisterInputAction("Back");
        InputDeviceManager.UnregisterInputAction("Vertical");
    }
}

Re: Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 12:15 pm
by LostTrainDude
Hi Tony,
Thanks a lot for your answer!

Just for clarity's sake: the issue would happen also if I removed the Dialogue Manager from the scene I wanted to test and I have a separate GameInputManager script, a singleton as well, that is in charge of registering \ unregistering the inputs in its OnEnable \ OnDisable methods.

That said, applying the check as you suggested makes it work, even though I'm experiencing another unexpected behaviour.

Given that I have "wired" only 3 of the gamepad buttons (X, Y, B) to three possible answers and one (A) to skip a dialogue line - also manually setting them up in the "Joystick Key Codes to Check" list - what happens is that, when I skip a line that occurs before a Response Menu, it automatically selects the first available answer (I suppose this is because the Selected GameObject in the EventSystem is always the button linked to the first answer).

In other words it's as if the button was reacting on "IsPressed" rather than on "WasReleasedThisFrame", to use Unity's own terminology.

I'm not sure whether this is something related to the EventSystem or it's just me doing something wrong :roll:

It's probably worth mentioning that I am currently using **both** the "legacy" and new Input Systems, even though 90% of what I do is bound to the new one.

In the meantime, thanks a lot again!

Re: Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 1:19 pm
by Tony Li
By "selected," do you mean it's clicking the button and using the response? Or "selected" in the Unity UI Event System sense, in that it's focusing that button so the next "Submit" input will click it?

Re: Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 1:39 pm
by LostTrainDude
The EventSystem focuses on that button every time the Response Menu appears, but usually doesn't automatically bind it to the A button and doesn't automatically "click" it when I skip the last dialogue line before a menu appears, like it is happening now. In other words, here *both* things happen: the EventSystem focuses on it, and clicks it.

If I wait without skipping any lines, the EventSystem will still focus on it, but won't automatically click it, and it would also still "bind" it to the A button too, rather than just to the X button.

I hope the explanation makes sense!

Re: Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 2:31 pm
by Tony Li
I suspect that it's not actually bound to the A button. Instead, the Submit input is mapped to the A button. When you press the Submit input (A button), the EventSystem clicks whatever is currently selected. (By select, I mean "focus" -- place the highlight on the button so that the next Submit input will click it.)

The Dialogue Manager's Input Device Manager component will auto-select the first response button if the Input Device dropdown is Joystick or if Always Auto Focus is ticked. This ensures that a button is selected so the player can navigate the buttons with the joystick. Unity's still working out kinks with the new Input System. It's possible that, when pressing A to continue past the subtitle, the first response button is being selected and then the Event System is interpreting the same A button press as a click on the response button.

If you don't want the Dialogue System to auto-select the first response button, set the Input Device dropdown to Mouse, clear the Joystick *** To Check lists, and untick Always Auto Focus. If you're controlling the mouse cursor visibility somewhere else, untick Control Cursor State.

Re: Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 2:42 pm
by LostTrainDude
It seems to be working as intended now! I will let you know if something else happens down the road but fingers crossed for it not to be the case :)

I suspect it is as you say, about the new Input System - especially considering I'm "guilty" of using one of its preview packages - but I'm happy that I could keep it as it is and make it work (again, hopefully).

Thanks a lot, as always, for your patience!

Re: Controller input only working when starting in specific scene

Posted: Fri Dec 04, 2020 2:47 pm
by Tony Li
Glad to help!