Need Help with Inventory Error

So I am new to coding and Unity in general, so I have been following Brackeys “Making an RPG in Unity” tutorial, and I have come across this error that I can’t find any information online to fix. In episode 6"

" at 1:03 he creates the script inventory.onItemChangedCallback… and when I saved this to unity, It came up with the error

[Assets\InventoryUI.cs(12,19): error CS1061: ‘Inventory’ does not contain a definition for ‘onItemChangedCallback’ and no accessible extension method ‘onItemChangedCallback’ accepting a first argument of type ‘Inventory’ could be found (are you missing a using directive or an assembly reference?]

here is my code… I don’t seem to have any misspellings, so I don’t really know what is going on. Thank you.

using UnityEngine;

public class InventoryUI : MonoBehaviour
{
    Inventory inventory;



    void Start()
    {
        inventory = Inventory.instance;
        inventory.onItemChangedCallback += UpdateUI;
    }

   
    void Update()
    {
       
    }

    void UpdateUI ()
    {
        Debug.Log("Updating UI");
    }
}

also here is my code from the actual Game Manager

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

public class Inventory : MonoBehaviour
{
    #region Singleton

    public static Inventory instance;

    void Awake()
    {
        if (instance != null)
        {
            Debug.LogWarning("More than one instance of inventory found!");
            return;
        }
        instance= this;
    }

    #endregion

    public int space = 20;

    public List<Item> items = new List<Item>();
    public bool Add(Item item)
    {
        if (!item.isDefaultItem)
        {
            if (items.Count >= space)
            {
                Debug.Log("Not enough room.");
                return false;
            }
            items.Add(item);


        }
        return true;
    }
    public void Remove (Item item)
    {
        items.Remove(item);
    }
}

As the error tells you, the problem is that your Inventory does not contain the onItemChangedCallback, which you try to access. I would assume that he added that in a previous episode and you maybe missed it?

The full inventory file is supposed to look like that (from the github in the video description):
https://github.com/Brackeys/RPG-Tutorial/blob/master/Finished Project/Assets/Scripts/Inventory/Inventory.cs

Edit: Yeah he adds that in episode 4 at 12:35. And yes, i had nothing better to do.

5 Likes

Thank you so much for taking the time! I don’t know how I could’ve missed that!

1 Like