Hold a link to a object in a list.,Reference a List item

I want to have a reference to an object in a list that won’t break if I add or remove other objects to the list.

I have ScriptableObject 's saved in a List. These ScriptableObjects are cards.

Cards are moved from List deck to List player1;
When the card is moved, a canvas image(gameobject) is added to the screen, that pulls the image from the card, however, there is no hard linking to that gameObject.
_
What I want to do is remove the correct card from the list when it is played.

For the first card, I can use player1.RemoveAt(i); but this will misalign all the other cards.

I know there MUST be a way, but I can’t find anything.

Thanks for any help

_
There is a way. Use a :heart: hash map :heart: - collection where an int,string etc can constitute a “reference” (similar to int index for a list) and order doesn’t matter.
_
Let’s say you map your cards like this:

Dictionary<int,MyScriptableObject> _map = new Dictionary<int,MyScriptableObject>();

So now when you add a card - create an unique key for it as well:

int key = System.Guid.NewGuid().GetHashCode();// not 100% unique, but good enough
_map.Add( key , card );

Store this key somewhere so your UI-input code can use it however it needs:

if( _map.TryGetValue(key,out var card) )
{
	_map.Remove( key );
	card.Use();
}
else Debug.LogWarning($"card '{key}' doesn't exists");