Skip to main content

Serialized Dictionary

A SerializedDictionary<TKey, TValue> is identical to a Dictionary<TKey, TValue> and is internally implemented as such (see the official documentation.) It should never be used where a normal Dictionary can be used and it's supposed to be used as a Serialized Field to show in the Inspector.

Serialized Dictionary Inspector

In the inspector, a Serialized Dictionary is a list of Key-Value Pairs. All entries after the first with the same Key are flagged as DUPLICATE and are ignored at runtime.

To define a Serialized Dictionary, use the following code snippet as example.

[SerializeField]
private SerializedDictionary<int, string> _dictionary;
note

The generic parameters TKey and TValue can be any type, but the Dictionary will show up correctly in the Inspector only if those types are Serializable.