Item still in list after deleting

Hi, I need some help. I checked the list and it is deleting the item in the list. It also sets all values to
null as wanted but when I set up the inventory with the list it gives back that
the “deleted item” is back in the list despite me not even seeing it in the inspector of the list.

Is Unity going too quickly through it?
Adding Items works but not deleting them.
Thank you for any help
The idea is to reset the inventory and load the list again with all non deleted items.

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

public class inventory_player : MonoBehaviour
{
    private void Awake()
    {
        DontDestroyOnLoad(this);
    }
    public List<pick_up_interactable> inventory_list;
    public GeneralManager manager;
    public AudioSource inventorySound;

    public GameObject InventorySlots;
    GameObject[] slots;

    public GameObject Descriptions;
    GameObject[] descs;

    Sprite no_sprite;
    public Color none_color;

    private void Start()
    {

        inventory_list = new List<pick_up_interactable>();
        no_sprite = null;
        slots = new GameObject[5];
        descs = new GameObject[5];
        none_color = new Color(0, 0, 0, 0);
        slots[0] = InventorySlots.transform.GetChild(0).gameObject.transform.GetChild(0).gameObject;
        slots[1] = InventorySlots.transform.GetChild(1).gameObject.transform.GetChild(0).gameObject;
        slots[2] = InventorySlots.transform.GetChild(2).gameObject.transform.GetChild(0).gameObject;
        slots[3] = InventorySlots.transform.GetChild(3).gameObject.transform.GetChild(0).gameObject;
        slots[4] = InventorySlots.transform.GetChild(4).gameObject.transform.GetChild(0).gameObject;

        descs[0] = Descriptions.transform.GetChild(0).gameObject;
        descs[1] = Descriptions.transform.GetChild(1).gameObject;
        descs[2] = Descriptions.transform.GetChild(2).gameObject;
        descs[3] = Descriptions.transform.GetChild(3).gameObject;
        descs[4] = Descriptions.transform.GetChild(4).gameObject;

    }
    //Functions: AddItem(), RemoveItem()
    public void WipeInventory()
    {

        for (int i = 0; i < inventory_list.Count; i++)
        {
            Debug.Log(i);
            slots[i].GetComponent<Image>().sprite = no_sprite;
            slots[i].GetComponent<Image>().color = none_color;

            descs[i].transform.GetChild(0).gameObject.GetComponent<Text>().text = "";
            descs[i].GetComponent<inventory_item_holder>().pick_Up = null;

        }
        SetUpInventory();
    }

    public void SetUpInventory()
    {
        for(int i = 0; i < inventory_list.Count; i++)
        {
            Debug.Log(inventory_list[i]);
            slots[i].GetComponent<Image>().sprite = inventory_list[i].inventory_sprite;
            slots[i].GetComponent<Image>().color = Color.white;

            descs[i].transform.GetChild(0).gameObject.GetComponent<Text>().text = inventory_list[i].name_of_object + "\n" + inventory_list[i].description_of_object;
            descs[i].GetComponent<inventory_item_holder>().pick_Up = inventory_list[i];
        }

    }

    public void AddItem(pick_up_interactable item)
    {
        if (inventorySound != null)
        {
            inventorySound.Play();
        }
        inventory_list.Add(item);
        WipeInventory();
    }

    public void RemoveItem(pick_up_interactable myitem)
    {
        for (int i = 0; i < inventory_list.Count; i++)
        {
            if (inventory_list[i] == myitem)
            {
                inventory_list.RemoveAt(i);
            }
        }


        WipeInventory();
    }
}

Your list is just a list. Unity knows nothing about that list. That list is just a list… it says “these are the things I contain.”

If you want something removed from the scene, you generally need to Destroy() it.

I dunno what all you have going on with those hard-wired numbers for children, but that’s gonna have a lot of problems if you start destroying them, because now the numbers won’t match.

Also, generally speaking:

These things (character customization, inventories, shop systems) are fairly tricky hairy beasts, definitely deep in advanced coding territory. They contain elements of:

  • a database of items that you may possibly possess / equip
  • a database of the items that you actually possess / equip currently
  • perhaps another database of your “storage” area at home base?
  • persistence of this information to storage between game runs
  • presentation of the inventory to the user (may have to scale and grow, overlay parts, clothing, etc)
  • interaction with items in the inventory or on the character or in the home base storage area
  • interaction with the world to get items in and out
  • dependence on asset definition (images, etc.) for presentation

Just the design choices of an inventory system can have a lot of complicating confounding issues, such as:

  • can you have multiple items? Is there a limit?
  • are those items shown individually or do they stack?
  • are coins / gems stacked but other stuff isn’t stacked?
  • do items have detailed data shown (durability, rarity, damage, etc.)?
  • can users combine items to make new items? How? Limits? Results? Messages of success/failure?
  • can users substantially modify items with other things like spells, gems, sockets, etc.?
  • does a worn-out item (shovel) become something else (like a stick) when the item wears out fully?
  • etc.

Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

Or… do like I like to do: just jump in and make it up as you go. It is SOFT-ware after all… evolve it as you go! :slight_smile:

Breaking down a large problem such as inventory:

“Combining a bunch of stuff into one line always feels satisfying, but it’s always a PITA to debug.” - Star Manta on the Unity3D forums