- Home /
Solved the problem on my own
Problem with removing an item from a list
I am using a list of the player's items and I'm having a problem with removing items from the list. When I remove an item as a part of a quest, it works perfectly but currently I'm trying to make a discard button to the inventory and suddenly the items don't get removed.
During quests I'm using this line of code and as I said, it works fine:
ItemDataBase._instance.RemoveItem (this.gameObject.GetComponent ());
(RemoveItem is a function in ItemDataBase and Item is a script attached to all items and it's where the list gets the variables of the item )
In the inventory I'm trying to use this:
ItemDataBase._instance.RemoveItem (selectedItem.gameObject.GetComponent ());
The code runs when a button is pressed and it seem like there shouldn't be a problem. I added print ("removed") inside the RemoveItem function to see if it actually runs and it does, the item just doesn't get removed. I also checked if the issue was with the selectedItem.gameObject.GetComponent ()- part but no. I printed out a variable from the Item component and it's correct so the code is finding the right thing.
I've tried using just ItemDataBase.list.Remove (selectedItem.gameObject.GetComponent ()); but nothing changes.
I really don't understand what could I am doing wrong.
Follow this Question
Related Questions
How can I remove an item ffrom a list. 1 Answer
A node in a childnode? 1 Answer
Unity add a item to a list? 2 Answers
Adding Item object to Inventory List 0 Answers
Removing objects from a list in C# 2 Answers