Dictionary creates copy, rather than references

I’m looking to create a dictionary to use strings to refer to bools reflecting whether or not an item is unlocked.

I thought I could do this with:

Dictionary<string, bool> hatDict = new Dictionary<string, bool>();

//the booleans I want to access already exist elsewhere. I just need a way to reference them from a string

        hatDict.Add("Cowboy", Variables.boughtHatCowboy);
        hatDict.Add("Cowgirl", Variables.boughtHatCowgirl);
        hatDict.Add("Fedora", Variables.boughtHatFedora);

//Then I'd like to use a transforms.name as the key to check the bools of whether or not the item is purchased

 foreach (Transform child in hatList)
        {
            if (hatDict[child.name] == true)
            {
                child.gameObject.SetActive(true);
            }
            else
            {
                child.gameObject.SetActive(false);
            }
        }

Only thing is when I set up the dictionary it seems to create it’s own instance of the bool using the originals value, so when I change the value of the dictionary it doesn’t update the original

Any suggestions how to get the dictionary to refer to another var rather than just take the value from it upon declaring?

Correct. Bool is a value-type, so it only stores the value, not a reference. Read here for more information. To store it as a reference, you would need to encapsulate it.

Also, it has nothing to do with the dictionary. Any time you set a bool to be equal to another bool, they don’t stay linked; rather, the current value of the source is applied into the value of the destination.