Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question New Input System Not Working

Discussion in 'Input System' started by Bl00dyFish, Sep 8, 2023.

  1. Bl00dyFish

    Bl00dyFish

    Joined:
    Mar 12, 2022
    Posts:
    70
    I decided to convert my game to use the new Input Manager, however, even after following multiple tutorials, nothing works. I even created a test function using the buttonSouth, but that didn’t work.


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class PlayerMove : MonoBehaviour
    {
    PlayerController controls;
    public float speed = 7;
    public float lerpSpeed = 5;
    Vector2 move;

    private void Awake()
    {
    controls = new PlayerController();
    controls.Gameplay.Test.performed += ctv => Test();
    controls.Gameplay.Move.performed += ctx => move = ctx.ReadValue<Vector2>();
    controls.Gameplay.Move.canceled += ctc => move = Vector2.zero;
    }

    void Update()
    {
    Vector2 m = new Vector2(-move.x,move.y) * Time.deltaTime;
    transform.Translate(m, Space.World);
    }

    void Test()
    {
    print("Hi");
    }

    }
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,199
    You need to
    .Enable()
    the generated C# action map via code.
     
    bugfinders likes this.
  3. Bl00dyFish

    Bl00dyFish

    Joined:
    Mar 12, 2022
    Posts:
    70
    yeah, I added that. It still doesn't work. Even with the test function.
     
  4. Holonet

    Holonet

    Joined:
    Aug 14, 2017
    Posts:
    84
    The code you posted won't even compile on its own, I don't think. PlayerController is not one of Unity's classes. If it's your own, then we have no idea what it does. Also, we don't know if you're using the Player Input Manager component in the scene and wiring up to your methods, if you're using Unity Events, etc...
     
  5. BrighturaStudios

    BrighturaStudios

    Joined:
    Nov 29, 2017
    Posts:
    5
    Can you elaborate on this? I have been working on a game and just got some UI built and it seems the event system isn't even picking up any UI elements.
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,199
    That doesn't seem related to my post/the original post. Mine was about, if you're using a generated C# Input Actions object, you need to call
    .Enable()
    on it after creating it.

    For UI elements you need to ensure there is a standalone input module when using the new Input system: https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-StandaloneInputModule.html
     
  7. xiennastudio

    xiennastudio

    Joined:
    Aug 2, 2023
    Posts:
    19
    For the Move, try instead of getting the value from performed, get it from Update like this:
    Code (CSharp):
    1.     void Update()
    2.     {
    3.         move = controls.Gameplay.Move.ReadValue<Vector2>();
    4.     }
    https://docs.unity3d.com/Packages/c...eferencing-the-actions-asset-in-the-inspector

    For the Button South it's difficult to know the issue, maybe show the screenshot of your PlayerController scheme to show how you set it.

    In the Input System Packages, Unity provide the sample for the basic Input Actions, maybe it can be a good reference.
    upload_2023-9-13_20-3-58.png

    upload_2023-9-13_20-5-3.png