One of Unity’s longest-requested features has finally arrived.
Until now, working with dictionaries in Unity usually meant relying on serialization callbacks, custom wrappers, or third-party extensions.
Unity now includes built-in dictionary serialization support, including a dedicated two-column Inspector view for editing keys and values.
If you want to try it out, find the latest Alpha here Unity Editor Alpha Releases or use the Unity Hub and install the pre-release Editor 6000.6.0a7 or later.
We’d appreciate your input on what works well and what needs improvement so we can address any issues before the final 6.6 release. Let us know in the comments below or file a bug via Help > Report a Bug in the Editor. Thank you.
Better late than never. Good to see this finally happening.
No by-reference serialization support is a bit limiting.
What level of property-drawer support is there?
Also when is built-in [SerializeReference] inspector support happening? How did Dictionaries happen before this? The serialization has been supported since Unity 2019.
I want to appreciate this but cannot left out the feeling that we have waste our time of 10+ years for not having this from the start and it was disprove every argument we ever have when we ask why unity not just have dictionary like this all the times I was got the response that it cannot be done because blablabla
Anyway, now the next is nullable struct and tuple, keep up your greatness,Thanks
I figured that would be the case as I assumed you’d be using PropertyField’s for them. Though what about replacing the drawer for the whole dictionary? Is PropertyAttribute.applyToCollection respected?
Also still want to know about [SerializeReference].
Happy to see native UI support for dictionaries. Including robust duplicate key handling, property drawers and prefab overriding. There’s also a DictionaryHeaderAttribute to customize column labels and split.
There are some major limitations, however. Hopefully Unity can improve some of them in the future, like adding support for multi-editing:
Multi-object editing isn’t supported. The Inspector shows a help box when more than one target is selected.
Since Unity records dictionary overrides using the serialized array index, editing a dictionary on a prefab asset can leave existing instance overrides applied to a different entry. For more information, refer to Overrides on arrays, lists, and dictionaries.
The Inspector sort order doesn’t change the serialized order, which always reflects insertion order.
Search and filter aren’t available in the Inspector for dictionary entries.
Great update! I have been waiting for this for a long time!
Slightly unrelated but would it also be possible to get a QoL update which allows generics in general to be serialized without having to do this workaround?
public class MyMonoBehaviour : MonoBehaviour
{
[SerializeField] private Generic<int> doesNotWork;
[SerializeField] private WorkAroundInt doesWork;
}
[Serializable]
public class Generic<T>
{
[SerializeField] private T tVariable;
}
[Serializable]
public class WorkAroundInt : Generic<int> {}
Edit: The part about the generics has already been fixed, I was wrong about it not being fixed yet. I never noticed due to mainly working in older versions.
Yes, we wanted to be upfront about the current limitations, as this is an initial version of Dictionary support. We plan to continue improving it over time and will introduce additional features incrementally.
We found that too many places existing public Dictionary fields was not intended to the serialized. This prevents some bad surprises so therefore you have to explicitly opt-in to serialization.
There are known limitations to serialization and the Inspector that has been discussed over the years, such as [SerializeReference]. We are actively revisiting many of those areas, but we prioritized dictionary support for the 6.6 release. We really appreciate you pointing out other areas of improvement, but we would like to keep the focus of this thread on Dictionary feedback/issues that we can address before the 6.6 release.