NullReferenceException with new input system

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.7396568--903395--ScriptErrorScreenShot.PNG
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

Well I’m guessing since you aren’t setting InputMaster controls anywhere, it’ll just be null.

Unless you specify it to be something somehow, it’ll stay null. Do you have to use InputMaster? Could you do the same with PlayerInput or InputAsset?

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.

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/QuickStartGuide.html

This should get your started on the basics of getting a read from your input.

edited: Fixed syntax

Are you positive you don’t have any compiler errors in the console? Even one prevents EVERYTHING from working.

Make sure your log console selector buttons are enabled. See this graphic:

Beyond that, as you already suspect, there is only one answer for ALL nullrefs.

The answer is always the same… ALWAYS. It is the single most common error ever.

Don’t waste your life spinning around and round on this error. Instead, learn how to fix it fast… it’s EASY!!

Some notes on how to fix a NullReferenceException error in Unity3D

  • also known as: Unassigned Reference Exception
  • also known as: Missing Reference Exception
  • also known as: Object reference not set to an instance of an object

http://plbm.com/?p=221

The basic steps outlined above are:

  • Identify what is null
  • Identify why it is null
  • Fix that.

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.