Object reference not set to an instance of an object

Hello I’m getting this error:

NullReference: Object reference not set to an instance of an object
PlayerUI.Update() (at assets/PlayerUI.cs:19)

This is my PlayerUI script:

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

public class PlayerUI : MonoBehaviour {

    [SerializeField]
    RectTransform thrusterFuelFill;

    private PlayerController controller;

    public void SetController(PlayerController _controller)
    {
        controller = _controller;
    }

    void Update()
    {
       
        SetFuelAmount(controller.GetThrusterFuelAmount ());
    }

    void SetFuelAmount(float _amount)
    {
        thrusterFuelFill.localScale = new Vector3 (1f, _amount, 1f);
    }
}

and this is is a snippet of my PlayerController script (where I get the method GetThrusterFuelAmount from):

    [SerializeField]
    private float thrusterFuelBurnSpeed = 1f;

    [SerializeField]
    private float thrusterFuelRegenSpeed = 0.3f;
    public float thrusterFuelAmount = 1f;

    public float GetThrusterFuelAmount()
    {
        return thrusterFuelAmount;
    }

Do you ever call the method SetController(PlayerController _controller)?
I don’t see it in your code and if you don’t set the controller variable you will get a NullReference.

if its this line, then controller is probably null there… it could be the Update runs before you set it with SetController()

SetFuelAmount(controller.GetThrusterFuelAmount ());

Basically it looks like you are not passing PlayerController as a parameter when you call SetController();