New input system doesnt work on Build?

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:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewInput : MonoBehaviour
{
    private InputMaster controls;
    private Rigidbody2D rb;

    [SerializeField] private float speed = 8f;
    private float horiz = 0f;

    private void Awake()
    {
        controls = new InputMaster();
        rb = GetComponent<Rigidbody2D>();
    }

    private void OnEnable()
    {
        controls.Enable();
        controls.PLAYER.DPAD.performed += dpad => horiz = dpad.ReadValue<Vector2>().x;
    }

    private void OnDisable()
    {
        controls.Disable();
    }

    private void Update()
    {
        rb.velocity = new Vector2(horiz * speed, rb.velocity.y);
    }
}
1 Like

Can you post more details about what you’re trying to do, what is expected result and what is observed result? Thanks

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:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewInput : MonoBehaviour
{
    private InputMaster controls;
    private Rigidbody2D rb;

    [SerializeField] private float speed = 8f;
    private float horiz = 0f;

    private void Awake()
    {
        controls = new InputMaster();
        rb = GetComponent<Rigidbody2D>();
    }

    private void OnEnable()
    {
        controls.Enable();
        controls.PLAYER.DPAD.performed += dpad => horiz = dpad.ReadValue<Vector2>().x;
    }

    private void OnDisable()
    {
        controls.Disable();
    }

    private void Update()
    {
        rb.velocity = new Vector2(horiz * speed, rb.velocity.y);
    }
}

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.

So how does it not work? Just no input? Or it spawns some errors/crashes?
Which version of input system?

It just doesn’t detect the input. There’s no crash.

I was using version 1.0.2.

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?

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?

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

private void OnEnable()
    {
        if (gameInput == null)
        {
            gameInput = new GameInput();
            gameInput.Gameplay.SetCallbacks(this);
        }

        gameInput.Gameplay.Enable();  
    }

I get the NullReferenceException(s).

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

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.

1 Like

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

 "com.unity.inputsystem" : "1.0.2",

to

 "com.unity.inputsystem" : "1.2.0",

Unity will automatically update the plugin after you edit it.

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:
Player.log

Begin MonoManager ReloadAssembly

  • Completed reload, in 1.725 seconds
    D3D11 device created for Microsoft Media Foundation video decoding.
    Initializing input.
    New input system (experimental) initialized
    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.

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.

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


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


(Console after entering play mode in-editor)


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

And here is the Relevant Code part:

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.

Hey there @ , 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.

1 Like

Hey @Harsh-NJ , thanks a lot!

This works for me.

2 Likes

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

public class Input : MonoBehaviour
{
    InputActions _input;
    InputAction _move, _jump;
    public bool JumpPressed { get; set; }

    Vector2 _moveInput => _move?.ReadValue<Vector2>() ?? Vector2.zero;

    void Awake()
    {
        _input = new InputActions();
        _move = _input.Player.move;
        _jump = _input.Player.jump;
        _jump.performed += JumpPerformed;
        _jump.canceled += JumpPerformed;

        _input.Enable();
    }
    void JumpPerformed(InputAction.CallbackContext context) => JumpPressed = context.performed;
}

Quite odd behaviour. If anyone has seen this?

Same here

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.

As far as I can say is take the Input.Enable out of OnEnable and put it into Awake. Worked for me so far.