Why does my class variable change?

I am having a problem with a variable thats changing and have no clue why.

I have three buttons with their own script that I activate in a script. The skill class is a scriptable object.
Everything looks good in the inspector and each button gets their respective skill, but when i click on any one of them the skill variable is always the last, for all three of them…

void ShowButtons(List<Skill> chosenSkills)
    {
        for (int i = 0; i < 3; i++)
        {
            if (i >= chosenSkills.Count) break;
            upgradeButtons_.SetActive(chosenSkills*);*_

}
}
----------
[SerializeField] Skill skill;

public void SetActive(Skill skill)
{
this.skill = skill;
gameObject.SetActive(true);
button.image.sprite = skill.card;
particles.SetActive(skill.isTalent);

SetText(skill.name, skill.description, skill.lvl, false);
}

public void OnClick()
{
IUpgrade upgrade = (IUpgrade)GlobalData.player.AddComponent(skill.script.GetClass());
upgrade.OnBuy(skill.prefabs[0]);
UpgradeManager.instance.AfterClick();
}

This is likely the result of a “quirk” in C#. Setting delegates in a for loop using the iterator itself as input will (generally) result in them all being set to the iterator’s last value used during that loop.

You might be able to solve the problem by creating temporary, local variables in the process:

for(int i = 0; i < 3; i++)
{
	int current = i;
	if(i >= chosenSkills.Count) // Doesn't need to change here
	{
		break;
	}
	upgradeButtons[current].SetActive(chosenSkills[current]);
}