How to get a List of references of instances in a static variable

I want a parent class to contain a static LinkedList with all Instances of the class so I can manipulate or search them all at once.
Unfortunately I do not understand Unity enough yet to get this to work.

This is an example of what I am trying to do.
I tried using gameObject instead of Character and even GetComponent() returns a nullpointer exception.

public abstract class Character : MonoBehaviour {

    public static LinkedList<Character> characters;
   
    void Start () {
        ChildStart();
        RegisterCharacter(this as Character);
    }
    public static void RegisterCharacter(Character c)
    {
        characters.AddLast(c);
        Debug.Log("Registred " + c.name);
    }
}

Can anyone help me please? Thank you :slight_smile:

Your characters list could be null.

public static LinkedList<Character> characters = new LinkedList<Character>();

To avoid this error generally: before you try to access any object’s members (like AddLast), check that it is not null.

if (characters == null)
    characters = new LinkedList<Character>();
characters.AddLast(c);

if (characters != null) {
    characters.AddLast(c);
}
else
    Debug.LogError("Reference is null!");