Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

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 and styling UI for prefabs.

SerializedProperty is used in conjunction with SerializedObject and Editor classes. See Also: SerializedObject class, Editor class.

#pragma strict
public class MyObject extends ScriptableObject {
	public var myInt: int = 42;
}
public class SerializedProperty extends MonoBehaviour {
	function Start() {
		var obj: MyObject = ScriptableObject.CreateInstance.<MyObject>();
		var serializedObject: SerializedObject = new UnityEditor.SerializedObject(obj);
		var serializedPropertyMyInt: SerializedProperty = serializedObject.FindProperty("myInt");
		Debug.Log("myInt " + serializedPropertyMyInt.intValue);
	}
}
using UnityEngine;
        
public class MyObject : ScriptableObject 
{
  public int myInt = 42;
}

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

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

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

Variables

animationCurveValueValue of a animation curve property.
arraySizeThe number of elements in the array. If the SerializedObject contains multiple objects it will return the smallest number of elements. So it is always possible to iterate through the SerializedObject and only get properties found in all objects.
boolValueValue of a boolean property.
boundsValueValue of bounds property.
colorValueValue of a color property.
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.
enumValueIndexEnum index of an enum property.
floatValueValue of a float property.
hasChildrenDoes it have child properties? (Read Only)
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)
isExpandedIs this property expanded in the inspector?
isInstantiatedPrefabIs property part of a prefab instance? (Read Only)
longValueValue of a integer property as a long.
nameName of the property. (Read Only)
objectReferenceValueValue of an object reference property.
prefabOverrideIs property's value different from the prefab it belongs to?
propertyPathFull path of the property. (Read Only)
propertyTypeType of this property (Read Only).
quaternionValueValue of a quaternion 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)
vector2ValueValue of a 2D vector property.
vector3ValueValue of a 3D vector property.
vector4ValueValue of a 4D vector property.

Public Functions

ClearArrayRemove all elements from the array.
CopyReturns a copy of the SerializedProperty iterator in its current state. This is useful if you want to keep a reference to the current property but continue with the iteration.
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 serialized property.
DuplicateCommandDuplicates the serialized property.
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 that allows you to iterator over the current nexting of a serialized property.
InsertArrayElementAtIndexInsert an empty 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 Functions

EqualContentsSee if contained serialized properties are equal.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961