- Home /
Question by
Glurak · Aug 05, 2014 at 12:10 PM ·
editor-scriptingsorting order
Values changed with Editor Script don't get saved
I have a simple editor script that alters the sortingOrder property of the SpriteRenderer of my GameObjects (which are mostly instantiated prefabs). It all works fine, however, after I saved my project and reopen it, it reverts all values back to what they were before I altered them.
Why is that and how can I make it persist?
if(GUILayout.Button("Fix Z-Order")) {
GameObject group = GameObject.Find("Doodads");
if(group == null)
Debug.LogError("GameObject not found!");
SpriteRenderer[] srs = group.GetComponentsInChildren<SpriteRenderer>();
foreach(SpriteRenderer r in srs) {
float y = r.transform.position.y;
r.sortingOrder = -(int)(y * 100);
}
}
Comment
Answer by Glurak · Aug 06, 2014 at 08:18 AM
Nevermind, I found the solution: For some reason, it is nowhere stated that you have to call UnityEditor.SetDirty(object)
after you modified object's value!