Search Unity

  1. Tune in to get all the latest Unity news live from Berlin on June 19, 6pm CEST. Set up a YouTube reminder!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Changed values do not persist

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

  1. thedevilsjester

    thedevilsjester

    Joined:
    May 21, 2018
    Posts:
    10
    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:
    260