Linq not working

I am trying to reorder a list based on how far each game object is away from the player. When I call it, nothing happens to the list and no errors are given.

I didn’t forget

using System.Linq;

These are my variables:

public GameObject player;
public List<GameObject> persons = new List<GameObject>();

Here is my function:

private void Reorder(Vector3 p)
       persons = persons.OrderBy(x => Vector2.Distance(p,x.transform.position)).ToList();

And I call it like this in the update function when I press a key


Why is it not working?

I don’t know if it’ll fix your issue but, use the Sort() method.

persons.Sort( (first, second) => 
    float distance1 = (first.transform.position - p).sqrMagnitude;
    float distance2 = (second.transform.position - p).sqrMagnitude;
    return distance1.CompareTo(distance2);

It’s better performance-wise and modifies the List in place. If you only need to know if one is further away than the other, use sqrMagnitude instead.