- Home /
What does SerializedProperty.Update exactly do?
Hello,
I understand that using SerializedProperty.ApplyModifiedProperties
will apply any modified values and changes been made to a SerializedObject
, otherwise the won't get reflected to the target object.
But I never understood why do I need to do a SerializedObject.Update
at the top of any editor script.
The doc is very poor, all it says "Update serialized object's representation." - you don't say!
What does this mean? what does it do? and why do I need it?
Thanks!
Well I do have to use that somewhere - but don't have the code to hand right now so I will try to remember and if no one posts then I'll look it up when I can.
I'm pretty sure that it updates the SerializedObject/Property representation from the variables you have set in the actual class.
Yeah so I use it when I have an inspector that uses serialized objects etc and I cause something to change with sideeffects using normal code during my processing. It updates the serialized object structure to represent the current state after the side effects.
Hmm, example? - "cause something to change" - hmm, sounds like calling Apply$$anonymous$$odifiedProperties
would apply the changes here?
No that applies the properties you've modified in the serialized object to the actual class, Update is the other way around.
So Update fetches the values from the class, to the object, and Apply will push the values back to the class? is that it?
Answer by whydoidoit · Feb 17, 2014 at 04:31 AM
Yep that was what I was trying to say ;)
Update = set serialized object stream now based on what is in the actual class
ApplyModifiedProperties = take what is in the object stream and put it in the class