Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug New input system doesnt work on Build?

Discussion in 'Input System' started by hyperkvlt, Oct 27, 2021.

  1. hyperkvlt

    hyperkvlt

    Joined:
    Aug 16, 2020
    Posts:
    38
    I know this is kinda common issue, I saw a few people complaining about this problem. But it seemed like the most of them haven't fixed it. And I haven't been able to fix this as well.

    Seems like the new input only works on Editor / Testing, but not after you build it.

    I am currently using unity 2019.4.31f and built the game on window 32_64. So, anyone got a good way to deal with it?


    The code I use:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewInput : MonoBehaviour
    6. {
    7.     private InputMaster controls;
    8.     private Rigidbody2D rb;
    9.  
    10.     [SerializeField] private float speed = 8f;
    11.     private float horiz = 0f;
    12.  
    13.     private void Awake()
    14.     {
    15.         controls = new InputMaster();
    16.         rb = GetComponent<Rigidbody2D>();
    17.     }
    18.  
    19.     private void OnEnable()
    20.     {
    21.         controls.Enable();
    22.         controls.PLAYER.DPAD.performed += dpad => horiz = dpad.ReadValue<Vector2>().x;
    23.     }
    24.  
    25.     private void OnDisable()
    26.     {
    27.         controls.Disable();
    28.     }
    29.  
    30.     private void Update()
    31.     {
    32.         rb.velocity = new Vector2(horiz * speed, rb.velocity.y);
    33.     }
    34. }
    35.  
     
    Last edited: Oct 28, 2021
    sirshelley likes this.
  2. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Can you post more details about what you're trying to do, what is expected result and what is observed result? Thanks
     
  3. hyperkvlt

    hyperkvlt

    Joined:
    Aug 16, 2020
    Posts:
    38
    My apologies.

    The input only works on Editor, but not on Build. I am using unity 2019.4.31f and built the game on window 32_64.

    The code I use:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewInput : MonoBehaviour
    6. {
    7.     private InputMaster controls;
    8.     private Rigidbody2D rb;
    9.  
    10.     [SerializeField] private float speed = 8f;
    11.     private float horiz = 0f;
    12.  
    13.     private void Awake()
    14.     {
    15.         controls = new InputMaster();
    16.         rb = GetComponent<Rigidbody2D>();
    17.     }
    18.  
    19.     private void OnEnable()
    20.     {
    21.         controls.Enable();
    22.         controls.PLAYER.DPAD.performed += dpad => horiz = dpad.ReadValue<Vector2>().x;
    23.     }
    24.  
    25.     private void OnDisable()
    26.     {
    27.         controls.Disable();
    28.     }
    29.  
    30.     private void Update()
    31.     {
    32.         rb.velocity = new Vector2(horiz * speed, rb.velocity.y);
    33.     }
    34. }
    35.  
     
    Last edited: Oct 28, 2021
  4. myRobotArms

    myRobotArms

    Joined:
    Jul 27, 2018
    Posts:
    1
    Using Unity 2020.3.14f1 and I have the new Input System in use, and it works fine when playing from editor, but when I build my game the inputs do not work. I have tried setting the Architecture in the build settings to bot x86 and x86-64 and it will not work. This is for a Windows build as the target platform.
     
  5. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    So how does it not work? Just no input? Or it spawns some errors/crashes?
    Which version of input system?
     
  6. hyperkvlt

    hyperkvlt

    Joined:
    Aug 16, 2020
    Posts:
    38
    It just doesn't detect the input. There's no crash.

    I was using version 1.0.2.
     
  7. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Try upgrading to 1.2.0 by changing manifest.json version string. How is your input action asset looks like for "PLAYER.DPAD"? Is Input system set to dynamic updates in Project Settings -> Input System?
     
  8. hyperkvlt

    hyperkvlt

    Joined:
    Aug 16, 2020
    Posts:
    38
    Thanks! It works after updating Manifest.JSON.

    But really, does this mean it can only be updated by script? Not package manager?

    Also, this one is my settings. Maybe I did something wrong?
     
  9. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Hello There,
    I'm having the exactly the same issue. Inputs are Working totally fine in editor, but when I build the Game (Windows x86) in Unity 2020.3.3f1 (InputSystem 1.0.2), the Inputs aren't working. The Development Console pops up in the build game (screenshot below).

    The issue is when I enable InputActions.GamePlay using
    Code (CSharp):
    1. private void OnEnable()
    2.     {
    3.         if (gameInput == null)
    4.         {
    5.             gameInput = new GameInput();
    6.             gameInput.Gameplay.SetCallbacks(this);
    7.         }
    8.  
    9.         gameInput.Gameplay.Enable();  
    10.     }
    I get the NullReferenceException(s).

    InputSystemError.png

    Note: You could probably see from the File paths in the Screenshot above that this is a game jam project, so please help me as quick as possible.

    Thanks and Regards,
    Harsh
     
  10. Here is how you can always install any version of any existing package from the package manager. You obviously should use the proper version number string. If you don't have the
    Add package by name
    option, you can use the
    Add package from git URL
    option too. In that case you need to compose the string like this:
    PACKAGE_NAME@<VERSION_NUMBER>
    so for example
    com.unity.inputsystem@1.2.0
    .
     
    ifisch likes this.
  11. hyperkvlt

    hyperkvlt

    Joined:
    Aug 16, 2020
    Posts:
    38

    Well I think I already mentioned this, but I already solve it by updating the plugin by script.

    Open manifest.json from your game project folder: ProjectName/Packages/manifest.json

    change
    Code (JavaScript):
    1.  "com.unity.inputsystem" : "1.0.2",
    to
    Code (JavaScript):
    1.  "com.unity.inputsystem" : "1.2.0",
    Unity will automatically update the plugin after you edit it.
     
  12. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Hi and thanks for reply.
    I tried updating to 1.2.0, but sadly, still no change...
    The only change is in the error message is that it is inputsystem@.1.2.0 instead of inputsystem@1.0.2

    Relevant Part from the Player Log:
    Begin MonoManager ReloadAssembly
    - Completed reload, in 1.725 seconds
    D3D11 device created for Microsoft Media Foundation video decoding.
    <RI> Initializing input.
    New input system (experimental) initialized
    <RI> Initialized touch support.
    NullReferenceException while resolving binding 'Move:1DAxis' in action map 'GameInput (UnityEngine.InputSystem.InputActionAsset):Gameplay'
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    UnityEngine.Logger:Log (UnityEngine.LogType,object)
    UnityEngine.Debug:LogError (object)
    UnityEngine.InputSystem.InputBindingResolver:AddActionMap (UnityEngine.InputSystem.InputActionMap) (at D:/Game-Jams/Game Off 2021/Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Actions/InputBindingResolver.cs:414)
    UnityEngine.InputSystem.InputActionMap:ResolveBindings () (at D:/Game-Jams/Game Off 2021/Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Actions/InputActionMap.cs:1169)
    UnityEngine.InputSystem.InputActionMap:ResolveBindingsIfNecessary () (at D:/Game-Jams/Game Off 2021/Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Actions/InputActionMap.cs:1065)
    UnityEngine.InputSystem.InputActionMap:Enable () (at D:/Game-Jams/Game Off 2021/Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Actions/InputActionMap.cs:500)
    GameInput/GameplayActions:Enable () (at D:/Game-Jams/Game Off 2021/Assets/Scripts/Input/GameInput.cs:338)
    InputReader:EnableGameplayInput () (at D:/Game-Jams/Game Off 2021/Assets/Scripts/ScriptableObjects/Input/InputReader.cs:69)
    InputReader:OnEnable () (at D:/Game-Jams/Game Off 2021/Assets/Scripts/ScriptableObjects/Input/InputReader.cs:28)
    (Filename: D:/Game-Jams/Game Off 2021/Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Actions/InputBindingResolver.cs Line: 414)
    NullReferenceException: Object reference not set to an instance of an object
    at UnityEngine.InputSystem.Utilities.TypeTable.LookupTypeRegistration (System.String name) [0x00023] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Utilities\TypeTable.cs:69
    at UnityEngine.InputSystem.InputBindingResolver.InstantiateBindingComposite (System.String nameAndParameters) [0x00008] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputBindingResolver.cs:645
    at UnityEngine.InputSystem.InputBindingResolver.AddActionMap (UnityEngine.InputSystem.InputActionMap map) [0x00497] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputBindingResolver.cs:345
    UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    UnityEngine.DebugLogHandler:LogException(Exception, Object)
    UnityEngine.Logger:LogException(Exception, Object)
    UnityEngine.Debug:LogException(Exception)
    UnityEngine.InputSystem.InputBindingResolver:AddActionMap(InputActionMap) (at D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputBindingResolver.cs:416)
    UnityEngine.InputSystem.InputActionMap:ResolveBindings() (at D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputActionMap.cs:1169)
    UnityEngine.InputSystem.InputActionMap:ResolveBindingsIfNecessary() (at D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputActionMap.cs:1065)
    UnityEngine.InputSystem.InputActionMap:Enable() (at D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputActionMap.cs:500)
    GameplayActions:Enable() (at D:\Game-Jams\Game Off 2021\Assets\Scripts\Input\GameInput.cs:338)
    InputReader:EnableGameplayInput() (at D:\Game-Jams\Game Off 2021\Assets\Scripts\ScriptableObjects\Input\InputReader.cs:69)
    InputReader:OnEnable() (at D:\Game-Jams\Game Off 2021\Assets\Scripts\ScriptableObjects\Input\InputReader.cs:28)
    (Filename: D:/Game-Jams/Game Off 2021/Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Utilities/TypeTable.cs Line: 69)
    NullReferenceException: Object reference not set to an instance of an object
    at UnityEngine.InputSystem.Utilities.TypeTable.LookupTypeRegistration (System.String name) [0x00023] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Utilities\TypeTable.cs:69
    at UnityEngine.InputSystem.InputBindingResolver.InstantiateBindingComposite (System.String nameAndParameters) [0x00008] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputBindingResolver.cs:645
    at UnityEngine.InputSystem.InputBindingResolver.AddActionMap (UnityEngine.InputSystem.InputActionMap map) [0x00b24] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputBindingResolver.cs:571
    at UnityEngine.InputSystem.InputActionMap.ResolveBindings () [0x00194] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputActionMap.cs:1169
    at UnityEngine.InputSystem.InputActionMap.ResolveBindingsIfNecessary () [0x00042] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputActionMap.cs:1065
    at UnityEngine.InputSystem.InputActionMap.Enable () [0x00022] in D:\Game-Jams\Game Off 2021\Library\PackageCache\com.unity.inputsystem@1.2.0\InputSystem\Actions\InputActionMap.cs:500
    at GameInput+GameplayActions.Enable () [0x00001] in D:\Game-Jams\Game Off 2021\Assets\Scripts\Input\GameInput.cs:338
    at InputReader.EnableGameplayInput () [0x00001] in D:\Game-Jams\Game Off 2021\Assets\Scripts\ScriptableObjects\Input\InputReader.cs:69
    at InputReader.OnEnable () [0x00030] in D:\Game-Jams\Game Off 2021\Assets\Scripts\ScriptableObjects\Input\InputReader.cs:28
    (Filename: D:/Game-Jams/Game Off 2021/Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Utilities/TypeTable.cs Line: 69)

    Thanks.
     
  13. I believe it is only working in the editor because you're trying to use it from a
    ScriptableObject
    .
    And if I'm right, the
    ScriptableObject
    in the editor will run the
    OnEnable
    when the asset is created or the project is loaded ant not when you hit play.

    In the build however, and obviously, the
    ScriptableObject
    only loads with the other stuff and only if anything is referencing it.
    I would highly recommend not to do this from a
    ScriptableObject
    and also, it would be a good idea to initialize your
    gameInput
    variable from
    Awake
    . This way you can avoid any kind of race condition and accidental reference to your
    InputActionAsset
    and maps and everything from
    Start
    calls and other
    OnEnable
    calls (there is no guarantee that one object's
    OnEnable
    will be called before the other object's.
     
  14. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Hi, this Scriptable Object Architecture is one of the things that I learned from the Unity open-project-1 (named ChopChop) community. I am using the exactly same method to get input, and ChopChop's inputs are working fine in build. Infact I have used this ScriptableObject input reader workflow in one of my ongoing Android game project, and the inputs on the device are also working...

    Many Scripts are referencing it for reading input.

    And for the confusion of whether the methods of InputReader asset are called or not, here are the console logs

    InputSystemError_ConsoleAfterCompilation.png
    (This is the Console output after in-editor code compilation)

    InputSystemError_ConsoleAfterPlayInEditor.png
    (Console after entering play mode in-editor)

    InputSystemError_DevBuildConsole.png
    (and this is the Console after a auto connected development build)

    And here is the Relevant Code part:
    InputReader_1.png InputReader_2.png

    As you can see I'm initializing gameInput in both Awake an OnEnable, and Awake is being called first in the build, but still with the errors...

    Thanks.
     
  15. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Hey there @Lurking-Ninja , thanks for you support, and the good news is it worked (finally)...
    What I just did, reading other threads, deleted the Move bindings in the Inputactions Asset, remade them as they were, and built the game. And inputs were working fine with the enabling function being called in OnEnable with no Awake method at all.

    I guess this was because of I created the asset using InputSystem 1.0.2 and then updated to 1.2.0 (as you suggested), this may have gave rise to incompability with that InputActions asset.

    Those with the same problem, just remove and remake the binding which is giving you the error in the build, in my case it was:
    Move:1DAxis

    Thanks.
     
    MilenaRocha likes this.
  16. HenryLeon

    HenryLeon

    Joined:
    Nov 4, 2019
    Posts:
    1
    Hey @Harsh-099, thanks a lot!

    This works for me.
     
    MilenaRocha and Harsh-NJ like this.
  17. Broudy001

    Broudy001

    Joined:
    Feb 12, 2020
    Posts:
    72
    I'm seeing a similar issue, though I'm using Visual Scripting for the state machine.

    I set up a simple test in a new project. A sphere with a rigid body and the all the state graph does is on fixed update check if the input button for jump has phase of performed, if true then add a force to the rb. Works fine in the editor, but after doing a build it doesn't work, no errors that I can see.

    If I move the functionality into fixed update in a script it works in the build

    Code (CSharp):
    1.  
    2. public class Input : MonoBehaviour
    3. {
    4.     InputActions _input;
    5.     InputAction _move, _jump;
    6.     public bool JumpPressed { get; set; }
    7.  
    8.     Vector2 _moveInput => _move?.ReadValue<Vector2>() ?? Vector2.zero;
    9.  
    10.     void Awake()
    11.     {
    12.         _input = new InputActions();
    13.         _move = _input.Player.move;
    14.         _jump = _input.Player.jump;
    15.         _jump.performed += JumpPerformed;
    16.         _jump.canceled += JumpPerformed;
    17.  
    18.         _input.Enable();
    19.     }
    20.     void JumpPerformed(InputAction.CallbackContext context) => JumpPressed = context.performed;
    21. }
    22.  
    Quite odd behaviour. If anyone has seen this?
     

    Attached Files:

  18. DBarlok

    DBarlok

    Joined:
    Apr 24, 2013
    Posts:
    268
    Same here
     
  19. JohnnyConnor

    JohnnyConnor

    Joined:
    Aug 10, 2020
    Posts:
    42
    I've been having and solving this issue several times in my project recently. Based on my experiences so far, Unity is probably falsely blaming the input system for the null reference errors happening in your code, meaning that the real issue has most likely something to do with your code.
    I suggest replacing the code triggered by your input events with simple Debug.Log string messages. If no errors occur, focus your investigation on the original lines of code you were using.
     
  20. Meltdragon

    Meltdragon

    Joined:
    Jan 25, 2017
    Posts:
    1
    As far as I can say is take the Input.Enable out of OnEnable and put it into Awake. Worked for me so far.