How do you find an Index of an Arrayed/Listed Object?

For example I have 5 Marbles and I want to find the 3rd Marble in my group.

Pretty Simple.

All I want to do is find out which Index is this GameObject in my group.

Such as.

public List<GameObject> Marbles;


But i’m pretty sure it isn’t that simple haha.

If anyone can help me i’d appreciate it.

I don’t get it, isn’t the index “2”? You’re just writing it there.

When you do “Marbles[2]” you get a GameObject reference, and GameObject doesn’t have a member called “index”.

If you already have an object reference and want to know the index where it can be found in a list there’s the “IndexOf” method: List<T>.IndexOf Method (System.Collections.Generic) | Microsoft Learn

You can simply use the IndexOf() of List : List<T>.IndexOf Méthode (System.Collections.Generic) | Microsoft Learn

public int IndexOf( item);

In you case your case (if i understood well) you have a list and a gameObject and you want to now the index of this gameObject in the List.

public List Marbles; int index = Marbles.IndexOf(Marbles[2]) //index will be equal to 2