Having Trouble with TurnManager for more than 2 turns.

Hi All,
I’m having a bit of trouble getting a turn system working. It is sort of an RPG turn based system where characters will act in an order determined by their reaction stat. What I’m doing is finding all “Player” tagged objects and adding them to a gameobject array and then trying to loop through that Array to add the objects in the right order into a SortedList. The problem I’m running into is when I go to add the Game object to the sortedlist I’m getting a NullReferenceException. I put a debug line in before this and it delivers the gameobject as expected. So I’m not sure why I’m having this issue.

 public SortedList<float, GameObject> UnitInfos;

   public void AddtoTurnList(GameObject g)
    {
        Debug.Log(g.name);
        UnitInfos.Add(g.GetComponent<UnitInfo>().Reaction, g);
    }

  void FindAndAddAllUnits()
    {
        units = GameObject.FindGameObjectsWithTag("Player");
        Debug.Log("test!");
        for (int i = 0; i < units.Length; i++)
        {
            AddtoTurnList(units*);*

}
}
Does anyone know of either a really good way to accomplish this or have any idea why how to fix this error? I’m not actually sure if the SortedList data structure is appropriate but I couldn’t find much help from the web on this kind of feature.

The null reference exception comes from either the SortedList being null or the UnitInfo component being null.

Has your SortedList been initialized?

UnitInfos = new SortedList<float, GameObject>();

Does every tagged object have a UnityInfo component? otherwise you can check this by writing

if (g.GetComponent<UnitInfo>() != null)
 UnitInfos.Add(g.GetComponent<UnitInfo>().Reaction, g);