hey ya’all ^^

having troubles with passing info into functions after the .clicked+= thingi,

here is what i tried within the onEnable function:

            for (int i = 0; i < ItemButtonClass.Length; i++)
                string Name = ItemButtonClass[i].nameOfItemsPicture;
                ItemButtonClass[i].button.clicked += DeleteItem(Name);

the error message shows this: Argument type ‘void’ is not assignable to parameter type ‘System.Action’

it does not matter, what is written within the var “Name”
every single button of this array is supposed to do slighlty sth else depending on which one it is, but i really dont want to write seperate functions for each single button and assign them seperatley x.x
so it would be really great to just be able to pass an argument here

in case it matters; here the code of the function, which is supposed to be added to the buttons when clicked:

    public void DeleteItem(string ItemName)
        C_Items.DeleteItemOfInventory(ItemName);
        LoadingItemsIntoScreen(true);

grateful for any ideas!

Delegates want the method itself subscribed to it, not the return value of the method.

delegate += Method;
// not
delegate += Method();

Now one option is to use an anonymous function and ‘capture’ the name string.

for (int i = 0; i < ItemButtonClass.Length; i++)
    string Name = ItemButtonClass[i].nameOfItemsPicture;
    ItemButtonClass[i].button.clicked += () => DeleteItem(Name);

However as this function is created on the fly, you can’t unsubscribe it later.

What I would do instead, is in your ItemButtonClass introduce its own event delegate, say, public event Action<string> OnItemButtonClicked;. Then said button(s) itself can subscribe to their down clicked callback and be able to pass their own name, and outside objects can subscribe to OnItemButtonClicked instead.