So I’ve been making some scripts that run in the editor to help set things up. But i’m noting that changes made by scripts executed in the editor aren’t saving.
Take the very simple example I’ve included below. All it does is destroy the object its on when you press the button in the editor. If you use it to destroy a gameobject then save the level and reopen it the object is back again. It happens both with things run by a customeditor and by behaviours with executinedit mode.
Nothing done by a script executed in the editor is getting saved, it’s all undone as soon as you save/reopen the scene; which is fairly annoying as it means i can’t use scripts to help set up things in my scene, and i need to set up large grids with lots of connections that would be incredibly tedious to do by hand. Is there something obvious i’m not understanding about running scripts in the editor? i could swear i’ve used scripts in editmode before and not had this problem
class DestroyMe : MonoBehaviour
{
}
[CustomEditor(typeof(DestroyMe))]
class DestroyMe_Editor : Editor
{
protected DestroyMe Owner
{
get
{
return (DestroyMe)target;
}
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Destroy now"))
DestroyImmediate(Owner.gameObject);
}
}