5
votes

This post is shamelessly a copy/paste from my post on the Unity Forums : https://forum.unity.com/threads/input-system-doesnt-trigger-anything-anymore.717386/, but Stack Overflow seems more active

TL;DR : InputSystem worked some days ago, don't trigger anything anymore, halp.

I tried the new Input System some days ago, and that's really neat ! I did a lot of stuff, trying to understand the best way to use it, and, in the end, I had a character jumping and moving everywhere, that was cool ! Then, I merged my code in our develop branch and went to bed.

Today, I want to continue my code, but my character doesn't move anymore, Actions are not triggered (even if inputs are detected in debugger) and I really don't know why. Either the code merge overwrote some important settings (I know what you're thinking and yes, the "Active Input Handling" is set on "Both" and I tried only running the preview) or I did something important during my little tests and I didn't realize.

So I decided to try to reproduce my steps on a fresh new project, maybe you guys can help me figure what do I do wrong ?

1/ Create a new 2D project (via the Hub)

2/ Install the latest Package (version 0.9.0)

3/ Click Yes on that message prompt to activate the new Input management in the settings Prompt

4/ Restart Unity Editor since it didn't restart even if the message said it would and check the project settings (yes, it's on "Both", and yes, my Scripting Runtime Version is 4.0) Settings

5/ Create a new GameObject and add a PlayerInput on it

6/ Click on "Open Input Settings" and create an "InputSettings" asset

7/ Click on "Create Actions..." to create my ActionMap asset

8/ Create a "TestAction" on my "Player" ActionMap and set it to the key "t"

[ATTACH=full]457769[/ATTACH]

9/ Create a new Script "TestScript" that contains a OnTestAction() method (that only logs "test") and enables the test map/action (just to be sure) :

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.PlayerInput;

public class TestScript : MonoBehaviour
{
    void Start()
    {
        InputActionMap playerActionMap = GetComponent<PlayerInput>().actions.GetActionMap("Player");
        playerActionMap.Enable();
        playerActionMap.GetAction("TestAction").Enable(); //Just to be sure
    }

    public void OnTestAction()
    {
        Debug.Log("test");
    }
}

10/ Pressing "Play" and spamming "T" like a madman to try to display a debug (note that, in the debugger, a User is created, my "t" presses are detected, my TestAction exists and is mapped on the "t" key but no debug is displayed Debug

It's probably a silly problem, but it's driving me crazy, what do I do wrong ? It's even more infuriating that it worked some days ago !

Additional information : - Switching the Input Management from "Both" to "New Input System (preview) does nothing - Checking in Update() is my action is enabled returns "True" every frame - Checking in Update() is my action is triggered returns "False" every frame - Using action.started/triggered/performed does nothing (I tried also switching to UnityEvent or C# events for this) :

public class TestScript : MonoBehaviour
{
    InputAction a;

    void Start()
    {
        InputActionMap playerActionMap = GetComponent<PlayerInput>().actions.GetActionMap("Player");
        playerActionMap.Enable();
        a = playerActionMap.GetAction("TestAction");
        a.Enable(); //Just to be sure
        a.started += OnTriggeredTestAction;
        a.performed += OnTriggeredTestAction;
        a.canceled += OnTriggeredTestAction;
    }

    public void OnTestAction()
    {
        Debug.Log("test");
    }

    public void OnTriggeredTestAction(InputAction.CallbackContext ctx)
    {
        Debug.Log("test triggered");
    }
}
  • Injecting directly the InputActionReference of my TestAction and using it does nothing
  • Forcing "Default Control Scheme" and "Default Action Map" does nothing
  • Using BroadcastMessage or UnityEvents doesn't work
3
I solved this by restarting the computer : it seems that the input system is based on how long your computer have been on, so a restart solved it. Notice the negative time in the debugger that is not supposed to be like this. - MetalFoxDoS
OMG... are you sure that was the problem? If that's true... that is scary. - Ph0t0n

3 Answers

1
votes

I don't know if this will work for you but it worked for me and I was having the same issue.

I had created 2 control schemes. Mobile and Pc. Mobile required touch screen and PC required keyboard and Mouse. Doing this made my Mobile input event stop firing. So adding the Gamepad to my Mobile Control scheme allowed the events to fire again.

TLDR. Check your control scheme make sure it allows for the inputs your binding to.

1
votes

You probably tried to import a new input system package for multiple input devices compatibility. These types of errors are due to conflict between old and new input system packages and are probably resolved in the latest updates.

To resolve this issue, Go to Edit -> Project Settings->Player->Under Other Settings under Configuration is the option Active Input Handling. Select Both. Unity will restart. Now your problem should be solved. You will be able to use old input system packages and the new ones also simultaneously.

0
votes

As of at least Unity 2020.1.2 and Input System 1.0.0 the input system will randomly stop working correctly. The only fix I'm aware of is restarting Unity.