How is it possible that my second list always has the same length that the first one even when it changes ?

Here is my code

private SelectionItems SI;

private List<GameObject> _selectedList;
private List<GameObject> _lastSelectedList;

private bool _needChange;

void Start () {
    
    _needChange = true;
    SI = GetComponent<SelectionItems>();
}
	
void Update () {

   // Get selected objects via a list
    _selectedList = SI.GetSelectedList();

    // Check if both lists have the same length
    if (_selectedList.Count == _lastSelectedList.Count)     { _needChange = false; }
    else                                                    { _needChange = true; }

    // Change the second list AFTER the if
    _lastSelectedList = _selectedList;
}

I want to understand why, _needChange is always equal to false, even when i change my selection in game.
I mean, indeed the length changes depending on my selection, but both lists always have the same length. When _selectedList.Count changes, _lastSelectedList.Count also changes BUT BEFORE THE IF and I don’t know why

Thanks for help :smiley:

Figured it out, should’ve known this sooner. Fix it by using

_lastSelected.AddRange(_selectedList);

Reason this happens is because you make last lastselected equal to selectedlist, this is because you should see it as a variable. If you put the Transform of an object inside a variable, it will change along with the Transform, this is what happened.