# DictionaryDisplayAttribute

> Configures how the Inspector presents a serialized Dictionary field: its column layout, the key and value header labels, and the initial key-column width.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Inherits from:** [Attribute](https://learn.microsoft.com/dotnet/api/system.attribute)

```csharp
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class DictionaryDisplayAttribute : Attribute
```

## Remarks

By default, the Inspector draws a serialized `Dictionary<TKey, TValue>` field as two columns with the headers **Key** and **Value**, and the key column takes up half of the available width. Apply `DictionaryDisplay` to a dictionary field to change the layout, override one or both header labels, or set the initial key-column width.

This attribute targets fields. It only takes effect when the field is a serialized dictionary that the built-in dictionary drawer renders in the Inspector.

Every setting is an optional named property:

* [layout](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/layout.md) selects the column layout. It defaults to [DictionaryLayout.TwoColumns](/engine/6000.7/script-reference/unityengine/dictionarylayout/twocolumns.md).
* [keyLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keylabel.md) sets the text above the key column. If empty, Unity uses the default label **Key**.
* [valueLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/valuelabel.md) sets the text above the value column. If empty, Unity uses the default label **Value**.
* [keyColumnFraction](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keycolumnfraction.md) sets the initial key-column width as a fraction of the total dictionary width. It's clamped to the range \[0.01, 0.99]; `NaN` is treated as 0.5.

The layout, labels, and key-column fraction only set the **initial** presentation. After the user changes the layout from the header context menu or drags the column divider, Unity persists their choice and ignores the attribute on subsequent draws. To return to the attribute's values, the user selects **Reset to Defaults** from the header context menu.

To configure a dictionary that has no field to decorate, such as the inner dictionary of a `Dictionary<int, Dictionary<string, float>>`, use [DictionaryDisplayForTypeAttribute](/engine/6000.7/script-reference/unityengine/dictionarydisplayfortypeattribute.md) at assembly level instead.

## Examples

```csharp
using System.Collections.Generic;
using UnityEngine;

public class LootTable : MonoBehaviour
{
    // Replace the default "Key" and "Value" column headers, and start with a wider key column.
    [DictionaryDisplay(keyLabel = "Item", valueLabel = "Drop chance", keyColumnFraction = 0.6f)]
    [SerializeField]
    private Dictionary<string, float> drops = new Dictionary<string, float>();

    // Stack each value under its key in a single column, and keep every value visible.
    [DictionaryDisplay(layout = DictionaryLayout.OneColumnWithValueVisible, keyLabel = "Name", valueLabel = "Item")]
    [SerializeField]
    private Dictionary<int, GameObject> rewards = new Dictionary<int, GameObject>();
}
```

## Properties

| Property                                                                                                         | Description                                                                                                           |
| ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [keyColumnFraction](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keycolumnfraction.md) | The initial width of the key column, as a fraction of the total dictionary width. Clamped to the range \[0.01, 0.99]. |
| [keyLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/keylabel.md)                   | The text displayed above the key column.                                                                              |
| [layout](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/layout.md)                       | The column layout the Inspector uses to present the dictionary.                                                       |
| [valueLabel](/engine/6000.7/script-reference/unityengine/dictionarydisplayattribute/valuelabel.md)               | The text displayed above the value column.                                                                            |

## Inheritance

**Inherited Members:**

* [Attribute.GetCustomAttributes(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-type\))
* [Attribute.GetCustomAttributes(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(MemberInfo)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo\))
* [Attribute.GetCustomAttributes(MemberInfo, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-boolean\))
* [Attribute.IsDefined(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-memberinfo-system-type\))
* [Attribute.IsDefined(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-memberinfo-system-type\))
* [Attribute.GetCustomAttribute(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(ParameterInfo)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo\))
* [Attribute.GetCustomAttributes(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-type\))
* [Attribute.GetCustomAttributes(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(ParameterInfo, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-boolean\))
* [Attribute.IsDefined(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-parameterinfo-system-type\))
* [Attribute.IsDefined(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-parameterinfo-system-type\))
* [Attribute.GetCustomAttribute(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-type\))
* [Attribute.GetCustomAttributes(Module)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module\))
* [Attribute.GetCustomAttributes(Module, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-boolean\))
* [Attribute.GetCustomAttributes(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-type-system-boolean\))
* [Attribute.IsDefined(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-module-system-type\))
* [Attribute.IsDefined(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-module-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-module-system-type\))
* [Attribute.GetCustomAttribute(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-module-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-type\))
* [Attribute.GetCustomAttributes(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Assembly)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly\))
* [Attribute.GetCustomAttributes(Assembly, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-boolean\))
* [Attribute.IsDefined(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-assembly-system-type\))
* [Attribute.IsDefined(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-assembly-system-type\))
* [Attribute.GetCustomAttribute(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.Equals(Object)](https://learn.microsoft.com/dotnet/api/system.attribute.equals)
* [Attribute.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.attribute.gethashcode)
* [Attribute.Match(Object)](https://learn.microsoft.com/dotnet/api/system.attribute.match)
* [Attribute.IsDefaultAttribute()](https://learn.microsoft.com/dotnet/api/system.attribute.isdefaultattribute)
* [Attribute.TypeId()](https://learn.microsoft.com/dotnet/api/system.attribute.typeid)
