Search Unity

Changed values do not persist

Discussion in 'Immediate Mode GUI (IMGUI)' started by thedevilsjester, Jun 9, 2018.

  1. thedevilsjester

    thedevilsjester

    Joined:
    May 21, 2018
    Posts:
    25
    I have a process that I need to run, in the editor, to automatically generate/fill in data on certain objects.

    Creating a new Tool Menu in the Editor allows me to do this, however my changes are only temporary. If the object I am changing is an instance of a prefab, it will revert back to the empty prefab values (even though changing those values does not break the prefab).

    I need these changes to stick when using a pre-fab. Is there some way to do this?

    I am creating the menu entry with the following code.
    Code (CSharp):
    1. public class NewBehaviourScript
    2. {
    3.     [MenuItem("Tools/Do Something")]
    4.     private static void NewMenuOption()
    5.     {                
    6.         GameObject[] things = GameObject.FindGameObjectsWithTag("thing");
    7.         foreach (GameObject thing in things)
    8.         {
    9.             thing.GetComponent<SomeThing>().someValue = 10;
    10.             EditorUtility.SetDirty(thing);
    11.         }
    12.  
    13.         EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
    14.     }
    15. }
     
    Last edited: Jun 9, 2018
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375