Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Can't get the new input system to work

Discussion in 'Input System' started by ZeHgS, Apr 29, 2022.

  1. ZeHgS

    ZeHgS

    Joined:
    Jun 20, 2015
    Posts:
    117
    SOLVED!! Sorry, I made a couple stupid mistakes including not attaching my PlayerControls scripts to any object. Duh!!! Thanks

    Hi everyone!

    I just tried migrating my game to the new input system. I am a bit of a newb so I am feeling quite lost. I'm following this tutorial https://gamedevbeginner.com/input-in-unity-made-easy-complete-guide-to-the-new-system/

    WHAT I DID

    1) Installed it in the Package Manager then changed my project settings

    2) Created Input Actions by right clicking in my project hierarchy

    upload_2022-4-28_22-45-56.png

    3) Assigned the inputs

    upload_2022-4-28_22-46-36.png

    4) Attached a Player Input component to a game object (I also tried "Invoke Unity Events")

    upload_2022-4-28_23-10-4.png

    5) Changed my code. I made two attempts. This is one way I was trying to get it to work without creating a specific script just to handle input:

    this is another way I tried after the first didn't work:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class PlayerControls : MonoBehaviour, PlayerInputActions.IPlayerControlsActions
    7. {
    8.     PlayerInputActions          input;
    9.  
    10.     MouseLook mouseLook;
    11.  
    12.     private void Awake()
    13.     {
    14.         mouseLook = GameObject.Find("Cameras").GetComponent<MouseLook>();
    15.     }
    16.  
    17.     private void OnEnable()
    18.     {
    19.         if (null == input)
    20.         {
    21.             input = new PlayerInputActions();
    22.             input.PlayerControls.SetCallbacks(this);
    23.         }
    24.         input.PlayerControls.Enable();
    25.     }
    26.  
    27.     private void OnDisable()
    28.     {
    29.         input.Disable();
    30.     }
    31.  
    32.     void PlayerInputActions.IPlayerControlsActions.OnMouseAxes(InputAction.CallbackContext context)
    33.     {
    34.      
    35.     }
    36.  
    37.     void PlayerInputActions.IPlayerControlsActions.OnZoom(InputAction.CallbackContext context)
    38.     {
    39.         mouseLook.ZoomIn();
    40.     }
    41.  
    42.     void PlayerInputActions.IPlayerControlsActions.OnFire(InputAction.CallbackContext context)
    43.     {
    44.  
    45.     }
    46.  
    47.     void PlayerInputActions.IPlayerControlsActions.OnPistol(InputAction.CallbackContext context)
    48.     {
    49.  
    50.     }
    51.  
    52.     void PlayerInputActions.IPlayerControlsActions.OnRifle(InputAction.CallbackContext context)
    53.     {
    54.  
    55.     }
    56.  
    57.     void PlayerInputActions.IPlayerControlsActions.OnShotgun(InputAction.CallbackContext context)
    58.     {
    59.  
    60.     }
    61.  
    62.     void PlayerInputActions.IPlayerControlsActions.OnReload(InputAction.CallbackContext context)
    63.     {
    64.  
    65.     }
    66.  
    67.     void PlayerInputActions.IPlayerControlsActions.OnGrenade(InputAction.CallbackContext context)
    68.     {
    69.  
    70.     }
    71. }
    72.  
    What am I doing wrong? Did I forget a step?
     
    Last edited: Apr 29, 2022