Unable to remove Vector2's inside of a list that have the same value as each other.

This following code doesn’t work the way that it should:

void Start()
    List<Vector2> myList = new List<Vector2>
        Vector2.up * 10f,
        Vector2.up * 10f


    foreach (var item in myList)

When I do a print out, it still says that there are two Vector2’s inside MyList that have the same value as each other. Wasn’t myList.Distinct().ToList() suppose to remove duplicates?

Distinct returns an enumerable with unique elements. You’re fine with the compiler as you aren’t required to have any variable receive the new enumerable you’ve created with Distinct, but your list there isn’t being changed.

You need to assign that new one back into that variable.

myList = myList.Distinct().ToList();