Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

SerializedProperty.GetDictionaryIgnoredEntries

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public DictionaryIgnoredEntries GetDictionaryIgnoredEntries();

Returns

DictionaryIgnoredEntries A DictionaryIgnoredEntries value whose two index arrays identify the ignored rows. Both arrays are empty when the property is not a serialized dictionary or when it has no ignored rows.

Description

Returns the duplicate-key and null-key placeholder rows of the serialized dictionary that this property refers to.

A serialized dictionary can hold 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. This method reports both kinds in a single pass and returns their positions in the dictionary's underlying serialized array of key/value pairs, split by reason into DictionaryIgnoredEntries.duplicateEntryIndices and DictionaryIgnoredEntries.nullKeyEntryIndices. The indices are in insertion order and stay stable across Inspector re-sorts because they reference the serialized array rather than the displayed row order.

Prefer this method over calling SerializedProperty.GetDictionaryDuplicateEntryIndices and querying the null-key rows separately when you need both sets: resolving the ignored-entry identifier is the expensive part of the operation, and this method does it only once.

This API is not supported when the underlying SerializedObject represents multiple selected targets, and throws an InvalidOperationException in that case. Multi-object editing of dictionaries is not supported.

Additional resources: DictionaryIgnoredEntries, SerializedProperty.GetDictionaryDuplicateEntryIndices, DictionaryDisplayAttribute, SerializedObject.

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CreateAssetMenu(fileName = "IgnoredEntriesStats", menuName = "IgnoredEntriesStats")] internal class IgnoredEntriesExample : 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 entries" from the // 3-dot menu to log the rows that the Inspector shows but the runtime dictionary drops. [ContextMenu("Log ignored entries")] private void LogIgnoredEntries() { using (var serializedObject = new SerializedObject(this)) { var dictionaryProperty = serializedObject.FindProperty(nameof(playerScores)); DictionaryIgnoredEntries ignored = dictionaryProperty.GetDictionaryIgnoredEntries(); Debug.Log($"'{nameof(playerScores)}' ignores {ignored.duplicateEntryIndices.Length} duplicate-key rows " + $"and {ignored.nullKeyEntryIndices.Length} null-key rows."); } } }