- Home /
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. :)
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 :)
Answer by Bunny83 · Jul 30, 2013 at 02:35 PM
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.
Ok. I don't have Unity Pro so I never had a chance to look at how Unity's serialization works, but now I think I get it :) Thanks for those very clear explanations :)