Search Unity

Saving Changes to .prefab from Custom Editor Window

Discussion in 'Editor & General Support' started by S3dition, Jul 14, 2015.

  1. S3dition

    S3dition

    Joined:
    Jan 6, 2013
    Posts:
    252
    So, I've written a nice custom editor for my friend to update prefabs with. The problem is that none of the changes are applied. As soon as the prefab loses focus, all the modifications are lost. I've tried:

    Code (csharp):
    1.  
    2. PrefabUtility.RecordPrefabInstancePropertyModifications(currentCreature);
    3. EditorUtility.SetDirty(currentCreature);
    4.  
    I can make a new prefab, delete a prefab, but I don't see anything to save changes on a prefab. Everything I've seen online deals with updating prefabs inside the game scene, but I want to change the actual prefab, not the instances of objects in the scene.

    Can anyone shine some light on this?
     
  2. S3dition

    S3dition

    Joined:
    Jan 6, 2013
    Posts:
    252
    Figured it out. I was having one of those moments. The variables will always go back to their defaults since they are private, and their defaults are always 0, null, etc. I just listed them all as public and hid them in the inspector. The save button is formatted as such:

    Code (csharp):
    1.  
    2.     if (GUILayout.Button("Save Prefab", GUILayout.Width(100.0f), GUILayout.Height(20.0f)))
    3.             {
    4.  
    5.                 AssetDatabase.RenameAsset(currentObjectPrefabPath, creatureStats.creatureName);
    6.                 AssetDatabase.SaveAssets();
    7.                 AssetDatabase.Refresh();
    8.             }
    9.  
     
    Last edited: Jul 14, 2015
    tatarochka likes this.