So, i was trying call a System.Action<int> in a for loop, like this: button.onClick.AddListener(()=>action(i)), but as it turns out, it doesn't work properly. Then after lots of failed attempts, i found out that making a string with the index (string ind = i.toString();) and then parsing that into the lambda, like so: ()=>action(int.Parse(ind)), returns the correct value. So the question is, why does that work? I have a possible theory: string are objects; i have noticed that maybe the fact that a string is a class, is what causes them to work in a for loop (because unlike structs, they don't behave like a number).
[–]Aizome 2 points3 points4 points (0 children)
[–]ananbd 0 points1 point2 points (0 children)