Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. 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:
    307