Search Unity

Bug Can't reorder components on prefab variant.

Discussion in 'Prefabs' started by daniel_lochner, Feb 24, 2021.

  1. daniel_lochner

    daniel_lochner

    Joined:
    Jun 9, 2016
    Posts:
    175
    Hi there,

    For some reason I can't reorder added components (indicated by the "+" icon) on prefab variants.

    In the following random example, I'm trying to move the
    AudioSource 
    component above the
    MeshRenderer 
    component. The only component on the base prefab is
    RandomComponent
    .
    upload_2021-2-24_20-9-46.png

    What's also strange is that I can use the context menu to move components up and down, but after reloading the inspector, it just resets back to what it was.
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Hi,

    There is actually a couple of bugs in play here. The dialog should not show up for added components, that is a bug. The fact that the components pops back after moving them with " Move up"/"Move Down" is also a known issue.

    Both issues are on our roadmap to get fixed but I can't tell you which release the fix will land in.
     
    mahdi_jeddi and daniel_lochner like this.
  3. browne11

    browne11

    Joined:
    Apr 30, 2015
    Posts:
    138
    Any update on this? Looking for a fix on 2019.4 LTS
     
    Last edited: Oct 9, 2021
  4. howardmealor

    howardmealor

    Unity Technologies

    Joined:
    May 21, 2021
    Posts:
    18
    Hi Cover-Club-Media. A fix is currently in progress but will unfortunately only appear in later releases due to its reliance on code which cannot be backported.
     
    browne11 likes this.
  5. browne11

    browne11

    Joined:
    Apr 30, 2015
    Posts:
    138
    Thanks for the update!
     
  6. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    Any news on this? It's driving me mad (2021.3.1).
     
    oli-2019 likes this.
  7. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    For anyone else who finds this thread. Here's a way to trick the Inspector into doing what I wanted to, but it doesn't fix the bug (drag-drop resorting, aka a core feature of the editor, stays broken):

    Code (CSharp):
    1. using UnityEngine;
    2. #if UNITY_EDITOR
    3. using UnityEditor;
    4. #endif
    5.  
    6. namespace com.noblerobot {
    7.  
    8.     public class ComponentSorter : MonoBehaviour {
    9.         public Component component;
    10.  
    11.         public bool moveUp = false;
    12.         public bool moveDown = false;
    13.  
    14.         #if UNITY_EDITOR
    15.         private void OnValidate(){
    16.             if (moveUp){
    17.                 moveUp = false;
    18.                 UnityEditorInternal.ComponentUtility.MoveComponentUp(component);
    19.             }
    20.             if (moveDown){
    21.                 moveDown = false;
    22.                 UnityEditorInternal.ComponentUtility.MoveComponentDown(component);
    23.             }
    24.         }
    25.         #endif
    26.     }
    27.  
    28. }
    Add this component to a GameObject, drag in a component, then click the checkboxes to sort up and down. I didn't use an editor script/custom drawer for this because I wanted to keep it as lightweight as possible.

    You'll also get the "Send Message can't be used with OnValiate" warning when using it, but this is a hack anyway so I don't care.

    Remove this component when you're done, but it doesn't cause any harm if you forget to. I suppose it could be turned into an Editor window instead of its own component to make it less tedius, but again, hack.

    For prefab variants with this issue, I assumed there are some corrupted values in the *.asset file (before making this fix, I tried copying/removing/pasting the components in the correct order, they went back to the wrong order again after saving the asset). Since this script doesn't fix the broken state while it can permanently change the order, I don't know [shurg Emoji].
     
    Last edited: Apr 30, 2022
  8. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    Welp, Nevermind. This doesn't work either. The components get sorted back into the "wrong order" after a few minutes of moving around the project.

    What the hell is going on here?
     
    Last edited: Apr 30, 2022
  9. Peter_Olsted

    Peter_Olsted

    Unity Technologies

    Joined:
    Apr 19, 2021
    Posts:
    75
  10. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    I can, but as is often the case with these things, I can't attach a project (because it's 10GB and contains things I shouldn't share), so I don't know what good it will do, sadly...

    I've recently updated from 2020 LTS to 2021 LTS, so I didn't realize this effected all the prefab varients in my project at first. I then assumed it was intended (if illogical) behavior in 2021 LTS, but now it seems like it is actually a bug.

    Is there anything other than a project-less bug report I can provide that might be helpful? Or, which assets/config files within a project would you guess might be most effective to submit with a bug report?

    Thanks!
     
  11. Peter_Olsted

    Peter_Olsted

    Unity Technologies

    Joined:
    Apr 19, 2021
    Posts:
    75
    The best case for us is a minimal reproduceable sample.
    So if you have a copy of the project, you can delete everything that is not relevant for the bug. I know this is not always possible nor easy, but it makes it a lot easier for us.

    Or if you can recreate the problem in an empty project, that is also wonderful for us.
     
  12. NobleRobot

    NobleRobot

    Joined:
    Jan 14, 2016
    Posts:
    56
    Yes, we all know what makes things wonderful and easier for Unity.

    It's just not practical.

    With a bug like this, figuring out "everything that is not relevant for the bug" can mean a week-long research project for the end-user.

    I was just hoping you might have some hints/guesses to make it a bit easier for me.

    Eh, so it goes. It's not a easy square to circle on your end, I get it.
     
  13. Peter_Olsted

    Peter_Olsted

    Unity Technologies

    Joined:
    Apr 19, 2021
    Posts:
    75
    I have looked more into the issue and I have learned that the issue should be fixed in the upcoming 2022.2 release and it will not be backported to older versions.

    Sorry about asking for a bug report.
     
    NobleRobot likes this.
  14. Matthu32

    Matthu32

    Joined:
    Mar 5, 2019
    Posts:
    4
    Hey so, on 2021.3.4f1
    I can't reorder components on a prefab variant, even if that specific component isn't present on the father, but I should be able to? Just trying to confirm this is the bug and I'm not just missng something
     
  15. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    108
    It's a bug.

    Why the fix isn't being backported to 2021 is beyond me. Yes, a bug in an essential part of Unity (inspector)... let's not fix it for the LTS version. Anyway it's on par with the average quality of Unity team's decision making, I suppose.
     
    sp-LeventeLajtai likes this.
  16. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Ugh, just ran into this. It's really annoying. Shame the LTS can't get any love.
    You can copy and paste the components around I guess.

    Edit - Right Click "Move Up" and "Move Down" works for me. That's okay, you need to have sniper level accuracy to dag and drop anyway :D
     
    Last edited: Mar 17, 2023
  17. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    108
    If you have a monolithic huge component it's okay. If you have a lot of components (like the name "component" implies) it takes forever to reorganize it.