Changes in variables from function triggered by editor script during edit mode are not applied.

Hello there,

I wanted to try automating some “manual labor” by writing an editor script that would allow me to call some specific functions on some scripts. Debug.Log messages confirm that the functions are indeed called successfully, and i can even see the changes on the script. The problem however is that the changes seem to not be saved after the function ends.

Even something as simple as the following setup doesn’t work:


//boring, myScript=target;
function OnInspectorGUI(){


var myBoolean:boolean=true;
function ToggleBoolean(){

myBoolean gets set to false and then back to true when i enter play mode or reload the level.
What could i be doing wrong?

Edit: serializedObject.ApplyModifiedProperties(); doesn’t seem to be working either, unless i’m using it wrong.

It should work if the variable is public and not private, are you sure it’s not being set to true elsewhere during gameplay?

Hey there, as you’re not manipulating the serialized properties using serializedObject.ApplyModifiedProperties() will not actually be applying any changes, I believe to serialize your changes you’ll need to use EditorUtility.SetDirty(myScript) after any variables are altered in editor script, in this case after myScript.ToggleBoolean()