Get "this" SerializedProperty ?

Hello there,

I’m working on something to make my life easier with Editor scripts and for a matter of simplicity of my code I’m looking for a way to work the same way with both SerializedObject and SerializedProperty. I could use an adapter pattern, but before I do that, I would like to know if there’s an easier way. :slight_smile:

Unless I am mistaken, there’s no way to use polymorphism to work the same way with SerializedObject and SerializedProperty when it comes to finding relative SerializedProperty. So I was wondering : is there a way to get a root SerializedProperty ? (that is to say a SerializedProperty that reflects its SerializedObject)

Thanks in advance for your answers :slight_smile:

No, that’s not possible. You should understand how the serialization actually works. If you have Unity pro, make sure you force text serialisation, then just open a prefab or a scene in a text editor.

A SerializedObject represents one object that is serialized on it’s own. Only Components and build-in reference types are actually serialized on their own. “Normal” custom serializable classes are serialized along is an actual SerializedObject. All the members of the custom class or array become properties of the SerializedObject. Between real SerializedObject it only holds references. So each SerializedObject is on it’s own but objects / values that are serializable but not SerializedObjects will become properties of the containing SerializedObject.