Version: 2023.2
LanguageEnglish
  • C#

SerializedProperty

class in UnityEditor

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

SerializedProperty and SerializedObject are classes for editing properties on objects in a completely generic way that automatically handles undo, multi-object editing and Prefab overrides.

SerializedProperty is primarily used to read or change the value of a property. It can also iterate through the properties of an object using Next. Additional resources: SerializedObject class, Editor class.

using UnityEngine;
using UnityEditor;

public class MyObject : ScriptableObject { public int myInt = 42; }

public class SerializedPropertyTest : MonoBehaviour { void Start() { MyObject obj = ScriptableObject.CreateInstance<MyObject>(); SerializedObject serializedObject = new UnityEditor.SerializedObject(obj);

SerializedProperty serializedPropertyMyInt = serializedObject.FindProperty("myInt");

Debug.Log("myInt " + serializedPropertyMyInt.intValue); } }

Properties

animationCurveValueValue of a animation curve property.
arrayElementTypeType name of the element in an array property. (Read Only)
arraySizeThe number of elements in the array.
boolValueValue of a boolean property.
boundsIntValueValue of bounds with integer values property.
boundsValueValue of bounds property.
boxedValueValue of the SerializedProperty, boxed as a System.Object.
colorValueValue of a color property.
contentHashProvides the hash value for the property. (Read Only)
depthNesting depth of the property. (Read Only)
displayNameNice display name of the property. (Read Only)
doubleValueValue of a float property as a double.
editableIs this property editable? (Read Only)
enumDisplayNamesDisplay-friendly names of enumeration of an enum property.
enumNamesNames of enumeration of an enum property.
enumValueFlagInt32 representation of an enum property with Mixed Values.
enumValueIndexEnum index of an enum property.
exposedReferenceValueA reference to another Object in the Scene. This reference is resolved in the context of the SerializedObject containing the SerializedProperty.
fixedBufferSizeThe number of elements in the fixed buffer. (Read Only)
floatValueValue of a float property.
gradientValueValue of a gradient property.
hasChildrenDoes it have child properties? (Read Only)
hash128ValueThe value of a Hash128 property.
hasMultipleDifferentValuesDoes this property represent multiple different values due to multi-object editing? (Read Only)
hasVisibleChildrenDoes it have visible child properties? (Read Only)
intValueValue of an integer property.
isArrayIs this property an array? (Read Only)
isDefaultOverrideAllows you to check whether his property is a default override.Certain properties on Prefab instances are default overrides.See PrefabUtility.IsDefaultOverride for more information.
isExpandedIs this property expanded in the inspector?
isFixedBufferIs this property a fixed buffer? (Read Only)
isInstantiatedPrefabIs property part of a Prefab instance? (Read Only)
longValueValue of an integer property as a long.
managedReferenceFieldTypenameString corresponding to the value of the managed reference field full type string.
managedReferenceFullTypenameString corresponding to the value of the managed reference object (dynamic) full type string.
managedReferenceIdId associated with a managed reference.
managedReferenceValueThe object assigned to a field with SerializeReference attribute.
minArraySizeThe smallest number of elements in the array across all target objects. (Read Only)
nameName of the property. (Read Only)
numericTypeReturn the precise type for Integer and Floating point properties. (Read Only)
objectReferenceValueValue of an object reference property.
prefabOverrideAllows you to check whether a property's value is overriden (i.e. different to the Prefab it belongs to).
propertyPathFull path of the property. (Read Only)
propertyTypeType of this property (Read Only).
quaternionValueValue of a quaternion property.
rectIntValueValue of a rectangle with integer values property.
rectValueValue of a rectangle property.
serializedObject SerializedObject this property belongs to (Read Only).
stringValueValue of a string property.
tooltipTooltip of the property. (Read Only)
typeType name of the property. (Read Only)
uintValueValue of an integer property as an unsigned int.
ulongValueValue of an integer property as an unsigned long.
vector2IntValueValue of a 2D integer vector property.
vector2ValueValue of a 2D vector property.
vector3IntValueValue of a 3D integer vector property.
vector3ValueValue of a 3D vector property.
vector4ValueValue of a 4D vector property.

Public Methods

ClearArrayRemove all elements from the array.
CopyReturns a copy of the SerializedProperty iterator in its current state.
CountInPropertyCount visible children of this property, including this property itself.
CountRemainingCount remaining visible properties.
DeleteArrayElementAtIndexDelete the element at the specified index in the array.
DeleteCommandDeletes the array element referenced by the SerializedProperty.
DuplicateCommandDuplicates the array element referenced by the SerializedProperty.
FindPropertyRelativeRetrieves the SerializedProperty at a relative path to the current property.
GetArrayElementAtIndexReturns the element at the specified index in the array.
GetEndPropertyRetrieves the SerializedProperty that defines the end range of this property.
GetEnumeratorRetrieves an iterator for enumerating over the visible child properties of the current property. If the property is an array it will enumerate over the array elements.
GetFixedBufferElementAtIndexReturns the element at the specified index in the fixed buffer.
InsertArrayElementAtIndexInsert an new element at the specified index in the array.
MoveArrayElementMove an array element from srcIndex to dstIndex.
NextMove to next property.
NextVisibleMove to next visible property.
ResetMove to first property of the object.

Static Methods

DataEqualsCompares the data for two SerializedProperties. This method ignores paths and SerializedObjects.
EqualContentsSee if contained serialized properties are equal.