Changing one instance of Rect in a class affects others

So I have this for loop and it out puts that at each iteration the rects are different but when the latter one is assigned it changes the previous ones.

so for example say on i=0 I get a rect x=0 y=0. Then on the second interation i=1 i get a rect x=50 y=50 if I look at Hudactions[0] it will now be a rect x=50 y=50. Why is this happening???

Each rect in hudaction is instantiated to a new rect. They are not referencing the same rect.

public void registerHudActions(params HudAction [] actions)
{
    HudActions.AddRange(actions);
    if (HudActions.Count < 1)
        return;

    Rect first = new Rect();
    int num = HudActions.Count / 2;

    first.width = hudSlotSize;
    first.height = hudSlotSize;
    first.x = Screen.width / 2 - (hudSlotSize * num) - (hudSlotOffset * num);
    first.y = Screen.height - hudSlotSize;
    
    
    
    for (int i = 0; i < HudActions.Count; i++)
    {
        if(i>0)
            Debug.Log("before i-1 :" + (i-1) + " " + HudActions[i-1].drawPosition); 
        HudActions*.drawPosition.width = first.width;*

HudActions*.drawPosition.height = first.height;*
HudActions_.drawPosition.x = first.x + (hudSlotSize * i) + (hudSlotOffset * i);
HudActions*.drawPosition.y = first.y;*
Debug.Log(“i :” + i + " "+HudActions*.drawPosition);*
if(i>0)
Debug.Log(“after i-1 :” + (i - 1) + " " + HudActions[i - 1].drawPosition);_

}
public List getHudActions()
{
List actions = new List();
HudAction action = new HudAction();
for(int i = 0; i < abilities.Count; i++)
{
iAbility ability = abilities*;*

action.OnClick = ability.getOnActivate();
action.texture = ability.getHudTexture();
action.isActive = isHudElementActive;
action.getTargetList = ability.getTargets;
action.TargetType = ability.getTargetType();
action.index = i;
actions.Add(action);
}
return actions;
}
}
these two functions are called by this
public void startTurn(IUnit u)
{
selectedUnit = u;
turnActive = true;
HUDManager.Instance.registerHudActions(u.getHudActions().ToArray());
}
The only think I can think of is that my abilties array in the function getHudActions() is populated like this:
abilities.Add(new TargetAbility(this));
abilities.Add(new TargetAbility(this));
abilities.Add(new TargetAbility(this));
But I don’t see how this messes with the draw position

I’m grabbing at straws here since I don’t see the problem in the code you’ve posted, but what we really need to see is where you initialize the HudActions array, not the HudAction class. Or anywhere you manipulate the array…sort it for example, or swap elements, or…

Or just write a quick nested loop that tests the references in HudActions to verify that all references are unique.