Hello people, I defined some dictionaries in script but I can’t see in inspector. Thanks for help.
2 Likes
Unity cannot serialize dictionaries by default. Make a struct/class that contains a key and a value, and expose a list of those objects. Then populate your dictionary from that list in Awake() or Start():
[Serializable]
public class KeyValuePair {
public MyKeyType key;
public MyValueType val;
}
public List<KeyValuePair> MyList = new List<KeyValuePair>();
Dictionary<MyKeyType, MyValueType> myDict = new Dictionary<MyKeyType, MyValueType>();
void Awake() {
foreach (var kvp in MyList) {
myDict[kvp.key] = kvp.val;
}
}
16 Likes