0 votes

I am trying to convert my inventory system from unity to Godot and when I try and grab an item in the inventory it gives me this error, I'm unsure why this is or how to fix it. I'm aware what the error means but I don't understand why its giving me it as it's a reference script not an Object? Any help would be appreciated


public class ItemSlot : Resource
public ItemResource item;
public int count;

public void Copy(ItemSlot slot)
    this.item = slot.item;
    this.count = slot.count;

public void Set(ItemResource item, int count)
    this.item = item;
    this.count = count;

public void Clear()
    this.item = null;
    this.count = 0;
public class Inventory : Resource
   [Export] public List<ItemSlot> inventoryItems = new List<ItemSlot>();


public class GameManager : Node
    public static GameManager instance;
    internal Inventory inventory;

    public override void _Ready()
        inventory = ResourceLoader.Load<Inventory>("res://Player/Inventory.tres");


 public class Toolbar : Node2D
        public ItemResource GetItem
                //Error occurs here:
                return GameManager.instance.inventory.inventoryItems[selectedTool].item;

Error Output:
E 0:00:00.790 ItemResource Toolbar.getGetItem(): System.NullReferenceException: Object reference not set to an instance of an object.
<C++ Error> Unhandled exception
<C++ Source> C:\Users\user\Documents\Godot\Projects\Assets\Scripts\Player\Toolbar.cs:28 @ ItemResource Toolbar.get
Toolbar.cs:28 @ ItemResource Toolbar.getGetItem()()
Toolbar.cs:80 @ void Toolbar.Equip()()
Toolbar.cs:19 @ void Toolbar.

in Engine by (19 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.