The serialized dictionary rows that the Inspector shows but the live runtime dictionary excludes.
A serialized dictionary can contain rows that have no place in the runtime Dictionary: rows whose key duplicates an earlier key, and null-key placeholder rows that the Inspector keeps so a user can edit them. Unity excludes both kinds when it builds the live dictionary, but preserves them in the serialized data so that no user edits are lost. This struct reports those ignored rows as indices into the dictionary's underlying serialized array of key/value pairs, split by the reason each row is ignored.
SerializedProperty.GetDictionaryIgnoredEntries returns a value of this type. Both DictionaryIgnoredEntries.duplicateEntryIndices and DictionaryIgnoredEntries.nullKeyEntryIndices are always non-null and refer to disjoint sets of rows. When a dictionary has no ignored rows, both arrays are empty.
Additional resources: SerializedProperty.GetDictionaryIgnoredEntries, SerializedProperty.GetDictionaryDuplicateEntryIndices, DictionaryDisplayAttribute.
using System.Collections.Generic; using UnityEditor; using UnityEngine;
[CreateAssetMenu(fileName = "IgnoredRowsStats", menuName = "IgnoredRowsStats")] internal class DictionaryIgnoredEntriesExample : ScriptableObject { [DictionaryDisplay(keyLabel = "Name", valueLabel = "Score", keyColumnFraction = 0.6f)] [SerializeField] private Dictionary<string, int> playerScores = new Dictionary<string, int>();
// Right-click the asset's Inspector header and choose "Log ignored rows" from the 3-dot menu. [ContextMenu("Log ignored rows")] private void LogIgnoredRows() { using (var serializedObject = new SerializedObject(this)) { var dictionaryProperty = serializedObject.FindProperty(nameof(playerScores)); DictionaryIgnoredEntries ignored = dictionaryProperty.GetDictionaryIgnoredEntries(); Debug.Log($"Duplicate-key rows: {string.Join(", ", ignored.duplicateEntryIndices)}"); Debug.Log($"Null-key rows: {string.Join(", ", ignored.nullKeyEntryIndices)}"); } } }
| Property | Description |
|---|---|
| duplicateEntryIndices | The serialized array indices of the duplicate-key rows that Unity could not merge into the live dictionary. |
| nullKeyEntryIndices | The serialized array indices of the null-key placeholder rows that the Inspector shows but the live dictionary excludes. |