- Home /
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:
MyEditorScript.js
//boring, myScript=target;
function OnInspectorGUI(){
if(GUILayout.Button("Test"){
myScript.ToggleBoolean();
}
}
//boring
OtherScript.js
//boring
var myBoolean:boolean=true;
function ToggleBoolean(){
myBoolean=false;
}
//boring
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.
Answer by Phles · Dec 14, 2014 at 03:38 PM
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()
Answer by SkaredCreations · Dec 14, 2014 at 03:36 PM
It should work if the variable is public and not private, are you sure it's not being set to true elsewhere during gameplay?
Your answer
Follow this Question
Related Questions
Lining up GUI 1 Answer
Add selection in GraphView via code 1 Answer
Adding functions in editor 1 Answer
Start/Stop Playmode from editor script 10 Answers