Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Controller bindings not working after Build

Discussion in 'Input System' started by SenorNeusAap, Sep 29, 2019.

  1. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    80
    Are there any news on this problem? I honestly find it very frustrating, my team invested a lot of time on this new input system and now it doesn't seem to work in build.
    I noticed that it randomly starts working after some time that the build is running but it is not acceptable
     
  2. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    80
    I tried this 5 year old project and here everything works just fine: it builds and it detects the gamepad (XBox One Controller) INSTANTLY.
    Why isn't the input system able to do that? From what I understand they both use the same XInput interface!

    This is the code I used to make my tests:

    Code (CSharp):
    1. using TMPro;
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4. using XInputDotNetPure; // Required in C#
    5.  
    6. public class Test : MonoBehaviour
    7. {
    8.     int playerIndex = -1;
    9.     GamePadState state;
    10.  
    11.     void Update()
    12.     {
    13.         var text = GetComponent<TMP_Text>();
    14.         var device = InputSystem.GetDevice<Gamepad>();
    15.         var current = Gamepad.current;
    16.  
    17.         // Find a PlayerIndex, for a single player game
    18.         // Will find the first controller that is connected ans use it
    19.         if (playerIndex == -1 || !state.IsConnected)
    20.         {
    21.             for (int i = 0; i < 4; ++i)
    22.             {
    23.                 state = GamePad.GetState((PlayerIndex)i);
    24.                 if (state.IsConnected)
    25.                 {
    26.                     Debug.Log($"GamePad found at index {i}");
    27.                     playerIndex = i;
    28.                     break;
    29.                 }
    30.             }
    31.         }
    32.         else
    33.         {
    34.             state = GamePad.GetState((PlayerIndex)playerIndex);
    35.         }
    36.  
    37.         text.text = $"GetDevice: {(device != null ? device.name : "<null>")}";
    38.         text.text += $"\nGamepad.current: {(current != null ? current.name : "<null>")}";
    39.         text.text += $"\nXInputDotNet: {state.IsConnected}";
    40.     }
    41. }
    42.  
    This is what I see as soon as I run the build:
    upload_2022-7-27_13-30-45.png

    ... and this is what I see after 40-50 seconds of doing nothing (just staring at the screen):
    upload_2022-7-27_13-31-4.png
     
  3. SecretTomodachi

    SecretTomodachi

    Joined:
    Nov 24, 2019
    Posts:
    24
    Did you figure out a solution to this? I'm experiencing a similar issue

     
  4. Oneiros90

    Oneiros90

    Joined:
    Apr 29, 2014
    Posts:
    80
    No solution yet but it happens just in my computer, so we ignored the problem for the moment
     
  5. GrimnirTheWhite

    GrimnirTheWhite

    Joined:
    Feb 9, 2019
    Posts:
    3
    This worked for me as well 2021.3f.11 Input System 1.4.4 All others fails for 2d vector in WebGL build except analog.
     
  6. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    287
    I have noticed that in the new input system, input devices are not necessarily fully working at Start. I added an explicit call to InputSystem.Update() in an Awake, so presumably there's some execution order nonsense going on.
     
  7. adamwilks

    adamwilks

    Joined:
    Apr 3, 2017
    Posts:
    27
    I currently initialize my input code using the OnEnable handler of a ScriptableObject which works fine when testing in the Editor environment but from a player build Gamepad.current and Gamepad.all are null and empty at the time of execution.

    This issue does not appear to affect the Input System UI Input Module which I currently use with a Canvas for the main menu system.

    Tests done with an Xbox controller connected via USB on Windows. Unity 2021.3.9f1 and Input System 1.4.2

    This seems to have solved my issue presumably by forcing device enumeration before my code runs. Thank you for the suggestion, this was most frustrating!

    Edit: Feels like a better solution would be to run my code when the game commences instead of at application startup when the assets are loaded, but I think I'd still call the Update method just to be sure enumeration has happened.
     
    Last edited: Jan 3, 2023
  8. adamwilks

    adamwilks

    Joined:
    Apr 3, 2017
    Posts:
    27
    After a little more digging I found some reference to a similar issue existing prior to release of 1.4 and apparently being fixed in either 1.4.0 (according to changelog) or 1.4.1 (according to issue tracker).

    Figured I'd test again with 1.4.4 (latest at this time) but the issue still exists.
     
  9. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    542
    2021 LTS and latest Input system. There is always the same bug where InputActions are not enabled in build and need to be enabled manually. This is DAMN annoying.

    Code (CSharp):
    1.             //BUG Player does not enable these correctly
    2.             if (Application.isEditor.Not())
    3.             {
    4.                 _settings.CyclePrev.action.Enable();
    5.                 _settings.CycleNext.action.Enable();
    6.             }
    7.  
    8.             _settings.CycleNext.action.performed += Next;
    9.             _settings.CyclePrev.action.performed += Prev;
    10.  
    11.  
     
  10. IBXCODECAT

    IBXCODECAT

    Joined:
    Feb 18, 2020
    Posts:
    1
    This is going to sound really stupid, but it worked for me. Make sure you enable your action maps with the `.Enable()` function
     
  11. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    542
    Exactly, however it is definitelly weird that it is needed in build and not in the editor.
     
  12. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    815
    in 2022.3 LTS same occurs, but not in the new input system but in the old. Wether it is in the player setting "both" or "old" it works perfect on editor it does not in build. I just updated from 2020.3 LTS where this worked properly. I find insane that such a critical thing is not adressed with high priority.
     
  13. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,960
    I guess they are tweaking controller stuff and breaking both old and new systems in one swift move. mFI controllers don't work properly in editor any more and I can't test controller stuff on a Mac using the Input Manager. This used to work correctly for many years, but now it doesn't, even though I doubt there are any intentional changes to the old input manager.
     
  14. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    815
    I reverted the project back to 2020.3 and stuff is again working as intended. will stay here for safety...
     
  15. krotevg

    krotevg

    Joined:
    Jul 15, 2020
    Posts:
    2
    Same problems:
    Keyboard works fine. Controllers doesn't work in Build Mode
    Unity 2022.3.8f, InputSystem 1.6.3 - have problems
    Unity 2021.3.22f, InputSystem 1.5.1 - no problems
     
  16. krotevg

    krotevg

    Joined:
    Jul 15, 2020
    Posts:
    2
    I also noticed:
    keyboard has same id(always is 1) in both modes (Editor and Build)
    but gamepad has different ids in Editor and Build Modes, but each session it has always the same id (in editor always 24, in build mode it is 22).
    I hope it can helps InputSystem developers.
     
  17. weiyuan1996

    weiyuan1996

    Joined:
    Aug 3, 2022
    Posts:
    2
    I'm using Unity 2020.3.48f1 with input 1.5.1. Keyboard works fine, but controller doesn't work in build. It has been 2024, any solutions on this?