Legacy Documentation: Version 2017.2 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

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

SerializedObject

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

SerializedObject and SerializedProperty are classes for editing properties on objects in a completely generic way that automatically handles undo and styling UI for prefabs.

SerializedObject is used in conjunction with SerializedProperty and Editor classes.

See Also: SerializedProperty class, Editor class.

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

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

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

Properties

contextThe context used to store and resolve ExposedReference types. This is set by the SerializedObject constructor.
isEditingMultipleObjectsDoes the serialized object represents multiple objects due to multi-object editing? (Read Only)
maxArraySizeForMultiEditingDefines the maximum size beyond which arrays cannot be edited when multiple objects are selected.
targetObjectThe inspected object (Read Only).
targetObjectsThe inspected objects (Read Only).

Constructors

SerializedObjectCreate SerializedObject for inspected object.

Public Methods

ApplyModifiedPropertiesApply property modifications.
ApplyModifiedPropertiesWithoutUndoApplies property modifications without registering an undo operation.
CopyFromSerializedPropertyCopies a value from a SerializedProperty to the same serialized property on this serialized object.
FindPropertyFind serialized property by name.
GetIteratorGet the first serialized property.
SetIsDifferentCacheDirtyUpdate hasMultipleDifferentValues cache on the next /Update()/ call.
UpdateUpdate serialized object's representation.
UpdateIfRequiredOrScriptUpdate serialized object's representation, only if the object has been modified since the last call to Update or if it is a script.

Did you find this page useful? Please give it a rating: