- Home /
Setting SerializedFields in editor from script
I have a GameObject which in OnValidate() (or in a function called by a button in the inspector) should do stuff to other GameObjects in scene. If my function affects Transforms it works fine, I can make the function modify the scene however I want, moving stuff and assigning parents.
However If I affect other objects' scripts' SerializedFields it does nothing, since in the inspector the value is changed but it is not saved, in fact if I play or save and reload the scene the values are not saved.
OnValidate() works for serialized fields on the same script that calls it, but how can I do a script which modifies SerializedFields of other objects and saves the changes? I couldn't find anything similar and it seems very weird, considering that it should be (at least I think) quite a relatively common thing to do
Your answer
![](https://koobas.hobune.stream/wayback/20220613053007im_/https://answers.unity.com/themes/thub/images/avi.jpg)