An Element with the same key: Adding multiple objects and their children to dictionary

I’m trying to go through a scene and take all objects with a specific tag, and then take all of the children within those objects and then add all of that to a dictionary. The problem is that at some point it adds another Key.

    SomeDictionary.Clear();
    GameObject[] fieldCollection = GameObject.FindGameObjectsWithTag("FieldImage");
    foreach (GameObject field in fieldCollection)
    {
        foreach (Transform child in field.transform)
        {
            if (child.tag == "Toggle")
            {
                SomeDictionary.Add(field.name, child.name);
            }
        }
    }

My thoughts are that the problem is related to the Foreach loops. Any help is appreciated

A dictionary is not just a collection of key-values-pairs. Keys in a dictionary have to be unique. There can only be one entry for each key. Since you use the “field” name as key inside the inner loop you most likely are using the same key for multiple childs. That’s not possible. You haven’t said what’s the actual point of your dictionary.