Custom Editor doesn't apply changes to a prefab instance (changes revert)

Edit: Solved. Just forgot to set it dirty… in all my scripts

Hello, this is actually an older problem that I didn’t bother fixing. However, it made me really hesitant to even use custom editors anymore. Actually, when I was making the final modifications to a game, every single time I was trying to edit - say text - of several objects, they would revert in play time to what the prefab’s value is. I eventually had to break the prefab connection, which isn’t really an efficient option.

So now that I’m on another new project in its early stages, I was wondering why this problem came up in the first place and how I can avoid it. It would be nice to make custom editors as I go.

(Also, does this have anything to do with how I have the default inspector at the end of every single one of my editor scripts?)
Here’s an example that I know that stopped working (…if I recall correctly, as I thought I commented it all out rather than deleting it to disable it for final changes):

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(GUIWindow))]
public class E_GUIWindow : Editor 
{
    // Flag variable for folds
    bool showDefault = false;    // Show default Inspector?
    bool customTextMesh = false;    // Choose something other than this object's TextMesh

    public override void OnInspectorGUI()
    {        
        // Get the current script and its values
        GUIWindow myTarget = (GUIWindow) target;
        
        // Get the current type of Terrain
        myTarget.thisWindow = (GUIWindow.TypeWindow)EditorGUILayout.EnumPopup(
            "Window Type: ", myTarget.thisWindow);
        
        EditorGUILayout.LabelField("-----------"); // Spacer/Separator
        
        // NECESSARY so text wraps around and creates an expanding box
        EditorStyles.textField.wordWrap = true;
        
        // Message to show if GUIWindow hasn't been assigned
        if(myTarget.thisWindow == GUIWindow.TypeWindow.None)
        {    
            EditorGUILayout.HelpBox("This currently does nothing! Absolutely NOTHIN!",
                                    MessageType.Warning);
        }
        
        // Settings if this is a SecretsIndicator window
        else if(myTarget.thisWindow == GUIWindow.TypeWindow.SecretsIndicator)
        {    
            EditorGUILayout.HelpBox("Secrets Indicator! Used for showing information on secrets!",
                                    MessageType.Info);
            
            myTarget.windowName = EditorGUILayout.TextField("Name of Window: ", myTarget.windowName);
            myTarget.message = EditorGUILayout.TextArea("Window Message: ", myTarget.message);
            
        }
        
        // Settings if this is an Info Menu
        else if(myTarget.thisWindow == GUIWindow.TypeWindow.InfoMenu)
        {    
            EditorGUILayout.HelpBox("Used for showing different information!",
                                    MessageType.Info);
            
            // Toggle a non-default Text Mesh or not
            customTextMesh = EditorGUILayout.Foldout(customTextMesh, "Choose Non-Default TextMesh?");
            if(customTextMesh)
            {
                EditorGUILayout.LabelField("TextMesh: Hover Affect");                        
                myTarget.thisText = EditorGUILayout.ObjectField(myTarget.thisText,
                                                                typeof(TextMesh), true) as TextMesh;
            }
            
            EditorGUILayout.LabelField("Window Title");
            myTarget.windowName = EditorGUILayout.TextField(myTarget.windowName);
            EditorGUILayout.LabelField("Message of the Window:");
            myTarget.message = EditorGUILayout.TextArea(myTarget.message);
        }
        
        // Settings if this is a DeleteData window, for deleting all data
        else if(myTarget.thisWindow == GUIWindow.TypeWindow.DeleteData)
        {    
            EditorGUILayout.HelpBox("Window for deleting all data... ='(",
                                    MessageType.Info);
            
            // Toggle a non-default Text Mesh or not
            customTextMesh = EditorGUILayout.Foldout(customTextMesh, "Choose Non-Default TextMesh?");
            if(customTextMesh)
            {
                EditorGUILayout.LabelField("TextMesh: Hover Affect");                        
                myTarget.thisText = EditorGUILayout.ObjectField(myTarget.thisText,
                                                                typeof(TextMesh), true) as TextMesh;
            }
            
            EditorGUILayout.LabelField("Window Title");
            myTarget.windowName = EditorGUILayout.TextField(myTarget.windowName);
            EditorGUILayout.LabelField("Message of the Window:");
            myTarget.message = EditorGUILayout.TextArea(myTarget.message);
        }
        
        // Settings if this is a WorldInner window
        else if(myTarget.thisWindow == GUIWindow.TypeWindow.WorldInner)
        {    
            EditorGUILayout.HelpBox("Used for giving the name and information of the current world",
                                    MessageType.Info);
            
            // Toggle a non-default Text Mesh or not
            customTextMesh = EditorGUILayout.Foldout(customTextMesh, "Choose Non-Default TextMesh?");
            if(customTextMesh)
            {
                EditorGUILayout.LabelField("TextMesh: Hover Affect");                        
                myTarget.thisText = EditorGUILayout.ObjectField(myTarget.thisText,
                                                                typeof(TextMesh), true) as TextMesh;
            }
            
            EditorGUILayout.LabelField("Window Title");
            myTarget.windowName = EditorGUILayout.TextField(myTarget.windowName);
            EditorGUILayout.LabelField("Message of the Window:");
            myTarget.message = EditorGUILayout.TextArea(myTarget.message);
        }
        
        // Settings if this is a Tabbed window
        else if(myTarget.thisWindow == GUIWindow.TypeWindow.Tabular)
        {    
            EditorGUILayout.HelpBox("Used for making tabs",
                                    MessageType.Info);
            
            // Toggle a non-default Text Mesh or not
            customTextMesh = EditorGUILayout.Foldout(customTextMesh, "Choose Non-Default TextMesh?");
            if(customTextMesh)
            {
                EditorGUILayout.LabelField("TextMesh: Hover Affect");                        
                myTarget.thisText = EditorGUILayout.ObjectField(myTarget.thisText,
                                                                typeof(TextMesh), true) as TextMesh;
            }
            
            myTarget.customTabSize = EditorGUILayout.Toggle ("Custom Tab Size?", myTarget.customTabSize);
            if(myTarget.customTabSize) // If using a custom tab size
            {
                myTarget.sizeMultiplier = EditorGUILayout.RectField(myTarget.sizeMultiplier);
                
                // Print input
                if(GUILayout.Button ("Print Input"))
                   {
                    Debug.Log("Current Input: " + myTarget.sizeMultiplier);
                }
                
                // Reset the sizeMultiplier to default
                if(GUILayout.Button ("Reset Size Multiplier?"))
                {
                    Debug.Log("Default Size: " + myTarget.defaultSize);
                    myTarget.sizeMultiplier = myTarget.defaultSize;
                }
            }
        } // end else if tabular
        // Settings if this is the Settings window [main menu]
        else if(myTarget.thisWindow == GUIWindow.TypeWindow.Settings)
        {    
            EditorGUILayout.HelpBox("This is the main menu's setting GUI Window",
                                    MessageType.Info);
        }
    
        EditorGUILayout.LabelField("-----------"); // Spacer/Separator
        
        // Code for showing the default Inspector
        showDefault = EditorGUILayout.Foldout(showDefault, "Show Default Inspector");
        if(showDefault)
        {
            DrawDefaultInspector();
        }
    }
}

This seems like a systematic error, as practically all my past editor scripts have been structured like this. Any possible reasons?
And thank you for helping, it means a lot to me :smile:

Disclaimer: I skipped right past the code. :stuck_out_tongue:

Are you checking whether changes are made and setting objects dirty when they’re detected? If Unity doesn’t know that something is dirty I don’t think it bothers to save anything for that object. When you enter/exit play mode the scene is serialized and de-serialized, so anything that the Editor doesn’t save gets lost, which would explain your issue.

Thanks, that’s exactly it. Ironically, I saw it while searching for why this issue was occurring, but when skimming past I saw that it wasn’t “necessary”. Yay for taking things out of context while skimming :wink: