Search Unity

Bug [Major-Always-ByDesign] Refactoring renaming functions, missing references, and no console warning

Discussion in 'Scripting' started by AlanMattano, Jun 19, 2020.

  1. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    TYPE
    Bug-type: Major
    Always: by begins
    Is more like a Wish Missing Feature

    DESCRIPTION
    In Unity is very easy to build or ship hiding bugs after refactoring renaming functions methods because missing references do not pop-up automatically in the console.

    STEPS
    • Make a script in Game Object A with a function method
    • Make a button in Game Object B that points to Game Object A function method
    • Rename the function method
    • Notice that nothing pops up in the console
    • Press play: Notice that nothing pops up in the console
    • Make a build and Play: Notice that nothing pops up in the console.
    • Hit the button: Notice that the button is not working

    ACTUAL
    If a function method is rename, buttons loose references. And the error is never shown in the console. No warning is presented to the user. The user cloud potentially plays the game and not find the bug until shipping.

    EXPECTED
    That after the function method has changed since a new "Missing" reference pops up in the button, that an Error o Waring message is displayed in the console.

    Related
    Forum Link: https://forum.unity.com/threads/how...ns-pointing-to-it-or-how-to-find-them.902069/



    MissingReference.png
     
    Last edited: Jun 19, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    This one is a perennial crowd-pleaser, I'm sure the source of MASSIVE amounts of undetected errors out there in the wild right this minute. Absolutely maddening.

    Unfortunately, as long as Unity relies on a separate IDE, it's unlikely to get a seamless solution anytime fast.

    For the rename-class problem, the key is to uncheck the "also rename classfile" option, then after renaming your class in the IDE, go into Unity and rename the .CS file (use copy/paste to get it 100% right!!!), then reopen the IDE with Assets -> Open C# Project.

    For the rename-method problem, if I know a method is used by animator callbacks or buttons, I actually grep the entire project prefabs and scenes for the given function name, and then hand-edit the YAML file directly and make the rename myself.

    It sucks, but knowing that a first world solution is likely a long way off, I've gotten pretty good at it. Plus, knowing how much work is involved helps me decide, "Eh, maybe I can live with the old name."

    Oh yeah: always use source control (git is AWESOME with Unity) and then if you rename with the above method, it's easy to roll back if you test quickly enough.
     
  3. I guess when Unity develop this, the same people who is demanding the fix of this "major bug" (really?) will be even more mad why the compilation time is so long when they enter play mode... or when they alt-tab back to Unity... or when open up the project...

    BTW, among other things this is why I use Rider. I just hit F2, rename my class and everything (including the filename, the references, everything) gets renamed unless I uncheck the checkbox to do so.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Best solution would be something entirely within the Unity editor: when there is a property that CAN be renamed, you have a button rename it in the Unity editor and it takes care of digging through everything. It would be able also to STOP you if you are trying to rename something that is in a "sealed" external asset, such as a .blend file or .max file, where you cannot rename those properties.
     
  5. I would be okay if Unity develops an automatism that looks for missing references during compile time. It just has to be off by default and everyone who wants to slow down their editor for this very minor convenience could do it on their term.
    We shouldn't ask for deliberate slowing downs and UI cluttering. Besides what stops you to rename any files/classes outside of the Editor? In your IDE? Or even in file browser? Should we ask for encoding the Project folders so people can't screw up their projects anymore?

    I'm really big fan of try to save people from themselves until a point. This is way behind that point because it affects the quality of life of all of us. Who actually knows how to rename a class properly. :)
     
    AlanMattano likes this.
  6. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    In my country, I can´t use Rider... because of payment madness!
    But (I presume) also using Rider, in this case, you will hit the same problem.
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    To avoid the problem, I've gotten into the habit of avoiding assigning most actions in the Inspector, doing this instead:
    Code (csharp):
    1. public Button btnDoAThing;
    2.  
    3. void Awake() {
    4.    btnDoAThing.onClick.AddListener(DoAThing);
    5. }
    6.  
    7. void DoAThing() {
    8. // ....
    9. }
    10.  
     
    Lurking-Ninja likes this.
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    ^ ^ This... This is the reason I wrote the datasacks module so that all I had to do was sprinkle the button responder and data output scripts all over a scene/prefab, then make the code just work against datasacks.

    If the designer or artist wants to refactor and they break it, then they get to fix it! "You break it, you bought it."
     
    AlanMattano likes this.
  9. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501