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

DictionaryIgnoredEntries

struct in UnityEngine

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

Description

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)}"); } } }

Properties

Property Description
duplicateEntryIndicesThe serialized array indices of the duplicate-key rows that Unity could not merge into the live dictionary.
nullKeyEntryIndicesThe serialized array indices of the null-key placeholder rows that the Inspector shows but the live dictionary excludes.