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

Resolved Input System Issues: no input

Discussion in 'Scripting' started by mv95_2020, Oct 25, 2020.

  1. mv95_2020

    mv95_2020

    Joined:
    Oct 25, 2020
    Posts:
    3
    Hi All,

    I've been stumped by the input system. I followed a YouTube tutorial (i think) to the letter, but when I playtest my game no input is detected from either my keyboard or my controller. However, I assigned the right stick to the Cinemachine input provider, and this works fine so it can't be the input devices themselves.
    Also, while trying to troubleshoot the issue suddenly the listen function of the input system stopped working.

    I have set up my inputs like this:


    and i'm using the following basic player movement script.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class PlayerMovementScript : MonoBehaviour
    7. {
    8.  
    9.     sysPlayerControls _controls;
    10.     Vector2 move;
    11.     public Rigidbody _player_rb;
    12.  
    13.     void Awake(){
    14.         _controls = new sysPlayerControls();
    15.         _controls.Player.Movement.performed += ctx => move = ctx.ReadValue<Vector2>();
    16.         _controls.Player.Jump.performed += ctx => Jump();
    17.         _controls.Player.Movement.canceled += ctx => move = Vector2.zero;
    18.     }
    19.  
    20.     void Update(){
    21.         Vector2 m = new Vector2(move.x,move.y) * Time.deltaTime;
    22.         transform.Translate(m);
    23.     }
    24.  
    25.     void Jump(){
    26.         Debug.Log("Attempt to Jump");
    27.         _player_rb.AddForce(0,20,0);
    28.     }
    29.  
    30.     void onEnable(){
    31.         _controls.Enable();
    32.     }
    33.  
    34.     void onDisable(){
    35.         _controls.Disable();
    36.     }
    37. }
    38.  
    Thanks in advance for any help
     
    Last edited: Oct 25, 2020
  2. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    679
    Where is
    sysPlayerControls
    defined?
     
  3. mv95_2020

    mv95_2020

    Joined:
    Oct 25, 2020
    Posts:
    3
    That's the generated C# class from the Input System, should I define that somewhere or is just having this script in the Assets enough?
     
  4. Stevens-R-Miller

    Stevens-R-Miller

    Joined:
    Oct 20, 2017
    Posts:
    679
    That tells me I need to do some homework.
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,342
    You're missing a _controls.Enable() call there.
     
    toskoxania likes this.
  6. mv95_2020

    mv95_2020

    Joined:
    Oct 25, 2020
    Posts:
    3
    Oh wow.. i didn't capitalize the o in OnEnable/OnDisable... Thanks for the input guys

    edit: However, the Listen function in the Input System window is still not working, any ideas on what might have caused that?
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,342
    It's a bit janky - I've also seen it no work at times. Not sure quite what would cause it.