I’m getting
NullReferenceException: Object reference not set to an instance of an object InputManager.FixedUpdate () (at Assets/Scripts/InputManager.cs46)
and
NullReferenceException: Object reference not set to an instance of an object InputManager.LateUpdate () (at Assets/Scripts/InputManager.cs50)
Here’s my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
public PlayerInput playerInput;
public PlayerInput.OnFootActions onFoot;
private PlayerMotor motor;
private PlayerLook look;
// Start is called before the first frame update
public static InputManager Instance { get; set; }
public InputManager inputManager;
private void Awake()
{
if (Instance != null && Instance != this)
{
}
else
{
Instance = this;
}
playerInput = new PlayerInput();
onFoot = playerInput.OnFoot;
motor = GetComponent<PlayerMotor>();
look = GetComponent<PlayerLook>();
onFoot.Jump.performed += ctx => motor.Jump();
onFoot.Crouch.performed += ctx => motor.Crouch();
onFoot.Sprint.performed += ctx => motor.Sprint();
}
// Update is called once per frame
void FixedUpdate()
{
//tell the playermotor to move using the value from our movement action.
motor.ProcessMove(InputManager.Instance.inputManager.onFoot.Movement.ReadValue<Vector2>());
}
private void LateUpdate()
{
look.ProcessLook(InputManager.Instance.inputManager.onFoot.Look.ReadValue<Vector2>());
}
private void OnEnable()
{
onFoot.Enable();
}
private void OnDisable()
{
onFoot.Disable();
}
}
I understand what a NullReferenceException is but I can’t figure out what is null or how to fix it