Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Changes made through a editor script on prefab instance are somehow forgotten?

Discussion in 'Scripting' started by Batman_831, Jul 10, 2019.

  1. Batman_831

    Batman_831

    Joined:
    Oct 17, 2014
    Posts:
    106
    [SOLVED]
    Ok, this something strange is happening here.
    I wrote a simple editor script to ease with some manual work. Here it is, pretty straight forward.

    Code (CSharp):
    1. [MenuItem("Tools/Refresh Visuals")]
    2.     public static void RefreshVisuals() {
    3.         GameObject[] devices = GameObject.FindGameObjectsWithTag("Device");
    4.         foreach (GameObject device in devices) {
    5.             Transform _ip_text = device.transform.Find("IP Label/Text");
    6.             if (_ip_text != null) {
    7.                 string ip = device.GetComponent<NetworkDevice>().ip;
    8.                 _ip_text.GetComponent<Text>().text = ip;
    9.             }
    10.         }
    11.     }
    12.  
    It's working absolutely fine except for one problem. Apparently, the script does its work and changes the text of UI labels to what I desire automatically but the changes are not permanent. That is, as soon as I reload the scene and/or restart unity, changes get revert back. Revert back to what you might ask. They get revert back to their prefab value. Yes, all these components are instanced from same prefab reference and apparently unity seems to forget that I made some change in the prefab instance.

    I can't seem to find a solution to this and unpacking prefab is obviously not what I want.
     
    Last edited: Jul 10, 2019
  2. Batman_831

    Batman_831

    Joined:
    Oct 17, 2014
    Posts:
    106