Version: Unity 6.6 (6000.6)
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, 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.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961