Built-in Dictionary Serialization and Authoring in Unity 6.6 Alpha

Hi everybody,

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.

Inspector Example

Get started

Declaring a serializable dictionary field is straightforward. Apply [SerializeField] and you’re done:

    [SerializeField]
    public Dictionary<string, int> items;

Documentation

Additional details are covered in the Manual: Script Serialization: Dictionaries — Unity 6 Manual

Feedback

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.

106 Likes

Good QoL update, thank you.

2 Likes

omg, thank you thank you, I’m assuming it’d work with Dictionary<string, someArray> too?

1 Like

Yes, works with any Unity serializable type

3 Likes

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.

7 Likes

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

1 Like

You have full property drawer support for both the key and value

3 Likes

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:

Limitations

  • 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.
4 Likes

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> {}

As stated by spiney199 having something like https://github.com/mackysoft/Unity-SerializeReferenceExtensions natively in the editor would also be great for QoL.

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.

4 Likes

an elderly woman with the words it 's been 84 years written on her face

28 Likes

Yes simply create your own drawer, this will override ours.

[CustomPropertyDrawer(typeof(Dictionary<,>))]
sealed class YourDictionaryDrawer : PropertyDrawer
3 Likes

That has been supported for a while now

Unity has been able to serialize conflated generics for a very, very long time now.

[SerializeReference] even supports it.

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.

6 Likes

Finally, time to say goodbye to my hacky serializable dictionary implementation.

Though I am curious why the decision of making the public dictionary not serialized by default, this makes it inconsistent with the rest of the types.

Now is the time to extend this serialization support to HashSets, tuples, KeyValuePairs and multidimensional arrays

2 Likes

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.

2 Likes

Finally \o/ \o/

Thank you very much!

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.

7 Likes