Serialize a Dictionary in Unity

Serialize a Dictionary in Unity

I like simple, and I like for Unity to handle as much of it as possible. To that end, are two solutions here. First, to just create a class or struct as a data container and make a List of that class or struct, or secondly, to implement your own dictionary that includes the inspectable bits. Where this becomes a better solution is that this new class can hold all the data you want and as long as the types can be serialized individually by Unity and is the same usage as a normal dictionary, then it will all be displayed in the inspector. I’ll provide examples below.