Search Unity

Resolved InputSystem: What am I missing?

Discussion in 'Input System' started by ZliVuk, Sep 22, 2021.

  1. ZliVuk

    ZliVuk

    Joined:
    Mar 24, 2018
    Posts:
    61
    1) Implemented new InputSystem (Package manger) and converted project to it
    2) Defined Input Action Asset with Scheme, Map, Actions
    3) Input System package set to Dynamic Update
    4) Implemented Player Input in my player GameObject, Behavior as Invoke Unity Events
    5) Added script to same player GameObject and made:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class PlayerMovementScript : MonoBehaviour
    5. {
    6.     public void PlayerMoveControl (InputAction.CallbackContext context)
    7.     {
    8.         Debug.Log(context.phase);
    9.         Debug.Log(context.ReadValue<Vector2>());
    10.     }
    11.    
    12.     public void PlayerJumpControl (InputAction.CallbackContext context)
    13.     {
    14.         Debug.Log(context.phase);
    15.     }
    16. }
    6) Added Events to Player Input for each of those controls (Actions in Maps of Scheme in Action Asset).
    Events do not get triggered.
    I have UI Button in same scene, with On Click event that does work so UI Events do work. Removing Button and Event object that were added for it does not solve problem. Those were added to test if Events work.
     
  2. LuiBroDood

    LuiBroDood

    Joined:
    Mar 13, 2019
    Posts:
    84
    it needs this???

    idk i followed a video input system annoying but i got it working lol


    Code (CSharp):
    1.  
    2.     void OnEnable() {
    3.         if(controls == null) {
    4.             controls = new Controls_Fps();
    5.             controls.playerfps.SetCallbacks(this);
    6.         }
    7.         controls.playerfps.Enable();  
    8.     }
    9.  
    10.     void OnDisable() {
    11.         controls.playerfps.Disable();  
    12.     }
     
    ZliVuk likes this.
  3. ZliVuk

    ZliVuk

    Joined:
    Mar 24, 2018
    Posts:
    61
    I followed this video:

    and found out that each scheme needs to have attached controller like Keyboard and then everything works.
    After I added Keyboard as required to Scheme everything worked.
     
    Ryoshi541 likes this.
  4. ZliVuk

    ZliVuk

    Joined:
    Mar 24, 2018
    Posts:
    61
    HOW TO MAKE InputSystem WORK:
    These are minimum requirements:

    1) Implement new InputSystem (from Package manger) and converted project to it
    2) Define Input Action Asset with Scheme, Map, Actions
    Scheme.png
    3) When defining new Scheme add controller to it!
    4) Input System package set to Dynamic Update
    project_settings_inputsystem_package.png
    5) Implement Player Input in my player GameObject, Behavior as Invoke Unity Events. InputSystem Settings can be set here also.
    PlayerInput.png
    6) Add script to same player GameObject like:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class PlayerMovementScript : MonoBehaviour
    5. {
    6.     public void PlayerMoveControl (InputAction.CallbackContext context)
    7.     {
    8.         Debug.Log(context.phase);
    9.         Debug.Log(context.ReadValue<Vector2>());
    10.     }
    11.  
    12.     public void PlayerJumpControl (InputAction.CallbackContext context)
    13.     {
    14.         Debug.Log(context.phase);
    15.     }
    16. }
    7) Add Events to Player Input for each of those controls (Actions in Maps of Scheme in Action Asset).
    PlayerInput_events.png
    Drag script from GameObject not script from asset browser.
    PlayerInput_drag.png
     
  5. ZliVuk

    ZliVuk

    Joined:
    Mar 24, 2018
    Posts:
    61
    Thanks for pointing me toward video and paying attention to small details.