Remove item from list when clicked on?

I have a list of items that show in my game as a list of buttons that can be clicked on to be removed. Right now my code isn’t removing any items or buttons. I’m not sure how to get it to remove the button/item I click on. I should note, the item I am trying to remove/delete is actually a deep copy of the original item. That may be part of the issue but I’m not sure how. Here is my code:

public class ActivityScrollList : MonoBehaviour {

     public void RemoveItem(Item itemToRemove, ActivityScrollList scrolllist)
     {
         for (int i = scrolllist.itemList.Count - 1; i >= 0; i--) {
             if (scrolllist.itemList  *== itemToRemove) {*

scrolllist.itemList.RemoveAt (i);
}
}
}

private void RemoveButtons(){
while (contentPanel.childCount > 0) {
GameObject toRemove = transform.GetChild (0).gameObject;
buttonObjectPool.ReturnObject (toRemove);
}
}

public void TransferItem(Item item){
RemoveItem (item, this);
}

public class ActivityBookButton : MonoBehaviour {
public Item item;

  •    private ActivityScrollList scrollList;*
    

void Start () {
button.onClick.AddListener (moveButton);
}

public void moveButton()
{
scrollList.TransferItem(item);

}
}
What is the issue with my code and why isn’t it removing the item from my list when I click it?

Hi @jcfrizz have you tried to modify your RemoveItem method? Maybe try to change RemoveItem method to look like this:

     public void RemoveItem(Item itemToRemove, List<Item> itemList)
      {
          itemList.Remove(itemToRemove);
      }

And change parameter of type ActivityScrollList to exact item list.

      public void TransferItem(Item item){
              RemoveItem (item, this.itemList);
  }

Let me know if that works.