Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. 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
  8. 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:
    12
    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:
    275