I am encountering a error with the new input system. This is my first time using it so sorry if I make any obvious mistakes. Here is my code
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public InputMaster controls;
void Awake()
{
controls.Player.Forwards.performed += ctx => Move();
}
void Move()
{
Debug.Log("Player wants to move");
}
}
It wont let me set the object even though its public.
I am following an Brackley’s tutorial Linked Here. I also had a the same error but in a different spot but deleting that fixed it. I haven’t made many games before so any help would be appreciated
InputMaster is the name of the script generated from the InputAction Asset. If i change it to anything else its spits out a different error or asks you to change InputMaster to what ever you set it to. I tried changing it to other things and it still wouldn’t let me set it in unity.
Okay I see, correct me if i’m wrong, but the tutorial looks outdated. InputMaster is now InputAsset in the newest input system. So you’d refer to as InputActionAsset controls, and it should allow you to set it in the inspector.
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
You need to figure out HOW that variable is supposed to get its initial value. There are many ways in Unity. In order of likelihood, it might be ONE of the following:
drag it in using the inspector
code inside this script initializes it
some OTHER external code initializes it
? something else?
This is the kind of mindset and thinking process you need to bring to this problem:
Step by step, break it down, find the problem.
Here is a clean analogy of the actual underlying problem of a null reference exception:
I ended up using PlayerInput instead but I had to rewrite the script as anything I set to public in that script wouldn’t show up. I am now trying the get events to work.