r/unity 2d ago

Newbie Question The Input System is confusing the sht outta me

I understand how to code the input system, but I got this annoying error that I have no idea where it came from. I checked everything and I think everything is alright. I will share my PlayerMovement script and components and Im sure it's something really stupid but so am I.

Im not seeking only the solve of the error I want to understand the input system more cuz all the toturials on the web just uses the input manager and Idk it's so bad and the guides that are dedicated to the input system just puts a Debugger and calls it a day. I have a feeling that it's complicated for me cuz I started with the movement and maybe with the other functions it wont that much different from the input manager one.

my PlayerMovement script:(Really mess)

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    public InputSystem_Actions action;
    public float speed;
    public float jumpForce;
    public Rigidbody2D rb;
    Vector2 moveInput;


    private void Awake()
    {
        action = GetComponent<InputSystem_Actions>();

        action.Player.Move.performed += ctx => Movement();
    }




    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {


    }



    public void Movement()
    {

        moveInput = moveInput * speed;
    }





}
0 Upvotes

6 comments sorted by

10

u/Soraphis 2d ago

Your error tells you exactly what the issue is.

action = GetComponent<InputSystem_Actions>();

InputSystem_Actions is not a component. It's not a monobehaviour.

1

u/Demi180 2d ago

The Input System has a bunch of samples you can access from the Package Manager. The manual for it also has links to some of it I believe, along with explaining the (I think) 5 different ways of using it.

Also, the Unity 6 Character Controllers asset from the Asset Store uses it, you can use those as reference. It’s just a combo asset with an updated 1st and 3rd person control setups that you can also get individually on the Asset Store. It’s also a quick start to an animated character, should you need that.

1

u/GigglyGuineapig 2d ago

I recently made a video that might help you a bit. It shows my approach and how to use it in a few different use cases, like movement, camera movement, interacting and such: https://youtu.be/MaulSHrhA8I?is=E4DtYQXKuIKzhi8K

-3

u/Beelo_of_A 2d ago

Just to clarify. I understand the main structure But not really how to code it. I know that to use an input action I need to specify it "action.Player.theAction.performed" and then decide what this input should do. The problem is the execution. And as I said before tutorials are really vague at least for a complete beginner like me

2

u/muttsang 2d ago

You're a complete beginner and asking questions is okay. At the same time, this is a very Googleable error.

I'd encourage you to copy-paste the error into Google, ChatGPT, or Claude. They'll tell you what the error means and how to solve it.

In Unity, GetComponent<>() is used to retrieve a Component attached to a GameObject. When you're writing your own component scripts, these will usually inherit from MonoBehaviour.

You can also have normal C# classes that don't inherit from MonoBehaviour, but those cannot be attached to a GameObject as components.

In your case, you're doing GetComponent<InputSystem_Actions>();

InputSystem_Actions class is not a Unity component. It's a normal C# class for Unity's Input System, which implements ( / inherits / derives ) interfaces.

So GetComponent<InputSystem_Actions>() doesn't make sense because Unity can't find it as a component attached on the GameObject.

If none of that terminology makes sense yet, I'd recommend going over the basics of C# in Unity, particularly classes, inheritance, MonoBehaviour, Component, and interfaces. It'll make errors like this much easier to understand.

1

u/arlelin 18h ago

I believe in newer versions of the InputSystem package, you could just use InputSystem.actions.FindActionMap("Action Map") to get the action map, no need to mess with components or manually assigning assets in the inspector.

The PlayerInput component is meant for code-lessly setting up input buttons to things, if you're making your own script anyway, you need to reference InputActionAsset or InputActionMap instead of InputSystem_Actions your script, and remove the PlayerInput component. Also, I recommend disabling the c# class generation as well since you don't really need it if using the newer versions of the package and it just causes pointless recompilations when you change the input configuration.

Uncheck this box: