Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Changed values do not persist

Discussion in 'Extensions & OnGUI' started by thedevilsjester, Jun 9, 2018.

  1. thedevilsjester


    May 21, 2018
    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.         }
    13.         EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
    14.     }
    15. }
    Last edited: Jun 9, 2018
  2. brownboot67


    Jan 5, 2013