Search Unity

Prefab script & reset

Discussion in 'Scripting' started by rockysam888, Jul 16, 2015.

  1. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Hi all,

    I have a script attached to a prefab.
    Whenever I modify and save the script (eg. the value of a public variable), the changes are not made immediately to the prefab. The prefab still show old values.
    I must use the reset option to reset the prefab.

    Why?

    Thanks in advance
     
  2. EliteWalrus

    EliteWalrus

    Joined:
    Aug 16, 2014
    Posts:
    44
    As far as I know once you save a script with a public variable, changing it within the script afterwards will not actually do anything. Try cutting it (ctrl + x) saving the script then pasting it back in change the values and save it again. This will reset the value in unity.
     
  3. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    2,147
    It would be utter chaos if that's what happened. Every single GameObject that uses that script would have its values changed, requiring you to go through your entire project and change all the values back.
     
  4. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Is there a way to update the script of all prefab or all instances automatically?
     
  5. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Anyone?
    Thanks in advance.
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    9,352
    What about writing an editor script? You could add a [MenuItem] that calls Resources.LoadAll() to load all resources into memory (if you have enough RAM) then iterates through Resources.FindObjectsOfTypeAll<YourScript>(), calling Reset() on them all. If LoadAll() is too heavy, you can use System.IO.Directory.GetFiles() to manually look at each file in your Asets folder.
     
  7. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Thanks a lot.
    @TonyLi: Your method is so advanced that I may try it in future.