Search Unity

Feedback [Input System] [PS4 Controller] Action occurs at start of the game without any key pressed

Discussion in 'Input System' started by MlleBun, Oct 6, 2019.

  1. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi,

    I'm confused with the new Input System's behaviour at start of the game.
    I have a simple action DebugInput binded to Cross [PS4 Controller] (I also tested on a keyboard mapping) which looks like this :

    upload_2019-10-6_20-43-10.png

    The following script just prints Jump when the DebugInput will be called. For me, it should be called only when I press on the Cross button, but here, I get a Jump print at the start of the game.

    Jump prints without Cross key pressed
    upload_2019-10-6_20-54-45.png

    Logically, if I put a jump animation, wouldn't the character execute the animation at the start of the game? Is there an issue with my code or am I missing something in the properties window (Interactions for ex?)?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class CubeControls : MonoBehaviour
    7. {
    8.     private PlayerControls controls;
    9.  
    10.     private void Awake()
    11.     {
    12.         controls = new PlayerControls();
    13.     }
    14.  
    15.     private void OnEnable()
    16.     {
    17.         // Debug Enabled.
    18.         print("Input System | " + controls.ToString() + " enabled.");
    19.  
    20.         controls.Gameplay.DebugInput.performed += obj => DebugInput();
    21.         controls.Gameplay.DebugInput.Enable();
    22.     }
    23.  
    24.     private void OnDisable()
    25.     {
    26.         // Debug Disabled.
    27.         print("Input System | " + controls.ToString() + " disabled.");
    28.  
    29.         controls.Gameplay.DebugInput.performed -= ctx => DebugInput();
    30.         controls.Gameplay.DebugInput.Disable();
    31.     }
    32.  
    33.     void DebugInput()
    34.     {
    35.         // Print Jump
    36.         Debug.Log("Jump");
    37.     }
    38. }
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    If the jump action triggers without the button being pressed, that'd be a bug. Could you file a bug with your setup through the Unity bug reporter including a stack trace of one of the calls to DebugInput?
     
  3. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi @Rene-Damm, thanks for your response. I reported the bug and I'll keep the thread updated. Thanks.
     
    Last edited: Oct 10, 2019
    Rene-Damm likes this.
  4. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Erratum : This post is fixed but not the new Input System behaviour at Start.

    There seems to be no response from Unity on this bug report I sent. @Rene-Damm, I'm currently merging from old to new Input System, hoping that the bug would be fixed. I have the new system on my character controller and the old on my cinemachine camera. I have the following binding :

    upload_2019-11-7_20-0-5.png

    Code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewInputSystemBug : MonoBehaviour
    6. {
    7.     private float inputX, inputZ;
    8.  
    9.     // Input System Actions
    10.     GameInputSystem inputSystem;
    11.     private Vector2 moveInput;
    12.  
    13.     private void Awake()
    14.     {
    15.         // Input System Actions.
    16.         inputSystem = new GameInputSystem();
    17.         inputSystem.Gameplay.Move.performed += ctx => moveInput = ctx.ReadValue<Vector2>();
    18.  
    19.         // Initialize PS4 Inputs
    20.         inputX = moveInput.x;
    21.         inputZ = moveInput.y;
    22.     }
    23.  
    24.     private void MoveAndRotatePlayer()
    25.     {
    26.         Vector3 input = new Vector3(inputX, 0, inputZ);
    27.  
    28.         // The player's move code =================
    29.         // ====================================
    30.     }
    31.  
    32.     // New Input System
    33.     private void OnEnable()
    34.     {
    35.         inputSystem.Enable();
    36.     }
    37.  
    38.     private void OnDisable()
    39.     {
    40.         inputSystem.Disable();
    41.     }
    42. }
    The character moves and rotates as expected with the old input System, but with the new, he starts running in a unique direction at the very start of the game (left due to relative-cam behaviour) and won't stop. And I haven't even touched the Left Stick.

    Also, when I try to 'tap' left/right/up/down, the stick acts like buttons. Tap up and you go up, tap down and you go down. When you try in-betweens (to go diagonal or to rotate), nothing happens. The character keeps its current direction.

    Any help is most welcome on this one. Thanks a lot.


    Fix

    upload_2019-11-9_15-38-58.png

    upload_2019-11-9_15-39-16.png
     

    Attached Files:

    Last edited: Nov 9, 2019
  5. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    From the first post, I made some modifications on the code, but the function is still called at the very start of the game even if I have'nt pressed on the button.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5. public class CubeControls : MonoBehaviour
    6. {
    7.     private PlayerControls controls;
    8.  
    9.     private void Awake()
    10.     {
    11.         controls = new PlayerControls();
    12.         controls.Gameplay.DebugInput.performed += ctx => DebugInput();
    13.     }
    14.  
    15.     private void OnEnable()
    16.     {
    17.         controls.Enable();
    18.     }
    19.  
    20.     private void OnDisable()
    21.     {
    22.         controls.Disable();
    23.     }
    24.  
    25.     void DebugInput()
    26.     {
    27.         // Print Jump
    28.         Debug.Log("Jump");
    29.     }
    30. }
     
    Last edited: Nov 9, 2019
  6. EnderManWiggins

    EnderManWiggins

    Joined:
    May 22, 2019
    Posts:
    29
    If you have your joystick plugged into a hub and not wirelessly that may be causing problems.
     
    jshadows2009 likes this.
  7. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi @EnderManWiggins, thanks for your anwser. But I think the joystick is ok. In fact, I tested with all my PS4 controllers, connected to the PC and the result is the same.

    The funny thing is that when I have the editor opened for a long time, the bug just disassapears. Yesterday night for instance, everything was ok. I just reopened the editor, and here it comes back again. This is a very annoying bug.

    But one thing though, keyboard keys work. No change of code, I simply bind a keyboard key and save the asset. The script event is not listened at the very start of the game. So I think this might be a general bug with a PS4/Gamepad controller.
     
    Last edited: Nov 11, 2019
  8. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Here's a demo between PS4 TouchPad and Space keyboard. The bug is almost on all PS4 buttons/triggers with the following script on a cube.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TestDevices : MonoBehaviour
    4. {
    5.     TestNewInputSystemDevices inputSystem;
    6.  
    7.     private void Awake()
    8.     {
    9.         inputSystem = new TestNewInputSystemDevices();
    10.         inputSystem.Test.ScaleCube.performed += ctx => ScaleCube();
    11.     }
    12.  
    13.     private void ScaleCube()
    14.     {
    15.         transform.localScale *= 1.1f;
    16.     }
    17.  
    18.     private void OnEnable()
    19.     {
    20.         inputSystem.Enable();
    21.     }
    22.  
    23.     private void OnDisable()
    24.     {
    25.         inputSystem.Disable();
    26.     }
    27. }
    28.  
    PS4 TouchPad binding
    upload_2019-11-11_13-26-44.png

    upload_2019-11-11_13-27-21.png

    Results : The ScaleCube script is called at the start of the game. So the cube scales to 1.1 immediately.
    upload_2019-11-11_13-37-59.png

    When simply changing the binding to a keyboard, the script is called only when Spacebar is pressed and not immediately at start.

    Keyboard binding
    upload_2019-11-11_13-27-51.png

    Result at Start
    upload_2019-11-11_13-39-7.png
     
    Last edited: Nov 11, 2019
  9. zenmasterchris

    zenmasterchris

    Joined:
    Mar 17, 2015
    Posts:
    3
    I'm experiencing the same issue with a PS4 Dualshock controller hooked up to my PC via Bluetooth. My XBox One controller works fine, but when my game starts using the PS4 controller it seems to fire all of my inputactions repeatedly non stop. It makes the game unplayable using a PS4 controller and my guess is also unplayable on a PS4.
     
  10. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi @zenmasterchris, it's weird that you have this bug now. Is it on buttons or axis? I noticed that the button issue was fixed when I updated back then to the newest release of Unity.

    If it can help, here are my PS4 bindings.

    On the touchpad, I only have this. I removed the Press interaction that I had on the previous post.
    upload_2020-6-8_18-39-44.png

    On my sticks
    upload_2020-6-8_18-40-32.png

    upload_2020-6-8_18-41-12.png

    I hope you solve this issue!
    Cheers