Search Unity

GameObjects not in same order as in Prefab?

Discussion in 'Prefabs' started by chanon81, Oct 28, 2018.

  1. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    @SteenLund: So I guess the answer is "no"?

    This leaves using the UI with nested prefabs in a fundamentally broken state for common use cases, because layout components depend on Game object order.

    Is there anything we can modify by hand to fix this on a case-by-case basis?
     
  2. Mythique

    Mythique

    Joined:
    Oct 18, 2015
    Posts:
    19
    So we are stuck with this bug for one more year if we need to stick to LTS release. That is a bummer.
     
  3. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Arg... just ran into this little gem.
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    I ended up fixing in my instance by pulling the parts out and created a new prefab that I inserted into the base prefab. Not elegant, but I don't have the time to futz around it. (in my case it is only in one area of the UI and isn't wide spread.)
     
    angrypenguin likes this.
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    I don't remember what I did. Possibly I just broke the prefab reference and thus will have to manually apply changes should it be relevant in the future.

    I'm surprised I haven't run I to this before. Though I kind of feel like I have, but in places where the order didn't matter.
     
    zombiegorilla likes this.
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    In my case it surfaced after I added a new (UI.Image) element to the base prefab (which I got through clicking down through from a parent to child to a variant to the base. The top most prefab had local changes and an element added to it locally). After that, one element was floating to the top (bottom of the hierarchy) only in one of the variants.

    What is annoying is that first I just simply tried to create a new prefab variant to replace the weird one. Didn't work, each new variant had the same problem. Tried renaming it, didn't work. Deleted and re-add it (with a new name)... same problem. Grrr.

    So ultimately, here is what I did, though I am not entirely sure which part "fixed" it. :
    1. pulled out all image/structural elements that required ordering and placed them in a new prefab.
    2. delete those parts from the original prefab.
    3. save everything and quit Unity.
    4. reopen and edit the base prefab by selecting it from the project (not drilling down).
    5. add the new prefab with the ordered parts.
    6. save and quit Unity.
    7. reopen and things appear correct.
    8. go back into the variants and parent prefabs and recreate local changes.

    I think going forward (until we upgrade to 2022 or whatever), is to be very careful adding elements to prefabs and only do so at the base and only after directly editing. (though don't know if that will prevent it).

    Yea, I wonder if that is the case for us as well. We don't use a lot of variants or deeply nested structures in the UI.
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    In our case we started using LayoutGroups in some places where we didn't previously. They position stuff based on Transform order, so now it matters where before it didn't.

    The use case here can't be that uncommon - just a bunch of objects laid out horizontally, and we need the layout to update based on the current language (ie: text of unknown length).

    I guess a workaround in this case which maintains prefab links would be to make a HorizontalLayoutGroup replacement which doesn't depend on Transform order.

    To be honest, a more fundamental gripe for me is having the combination of Transform-order-dependent UI functionality and immutable Transform ordering in prefabs in the first place. Even when this bug isn't impacting things it's a pain to work with. Having a "Layout Order" property in LayoutElement would fix that...
     
    zombiegorilla likes this.
  8. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    We (by "we" I mean my current and last two teams, and folks who worked on my current project before me) have been using layoutGroups since they have been around. With one exception, a custom layout control, we have depended on order since we started UI. (In fact, my current project absolutely abuses layoutGroups, I have been trying to remedy that when I can...sigh). This is the first time I have encountered (or noticed) this error, and we have only started using prefab variants. My working guess was that it was related to variants for that reason. I may be completely wrong.

    Certainly more control would be better. Personally the order thing has never bothered me, as it kinda how 2d as always sort of worked. Web, flash, other game UI, etc. Though.. many of those also do have a way alter it if needed.
     
  9. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    We've got variants in play. I'm pretty sure they're a bit further up the hierarchy, but it could still be a factor.

    It's fine in and of itself. The bit which irks me is when I run into: "Children of a prefab instance cannot be deleted or moved, and components cannot be reordered."

    Given that there are good reasons for the system to depend on the order of Transforms I'd have thought that keeping that order malleable would be a fundamental requirement.
     
    zombiegorilla likes this.
  10. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Any input/advice on what triggers the problem? So we can avoid it until the fix comes (and we upgrade to that version).
     
  11. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Agreed, especially with UI. I do seem to remember someone (@superpig maybe?) providing an explanation as to why it wasn't malleable. Though I don't remember the details. I just mentally filed it under "not gonna change anytime soon". ;)
     
  12. BlinksTale

    BlinksTale

    Joined:
    Dec 15, 2013
    Posts:
    13
    What an awful bug - I'm sorry to the Unity team for it being such a mess, but glad 2022 will have a fix. For now, the "Move to Front" solution on the Rect Transform worked for me - just has to be applied to the misordered child in the broken instance instead of the prefab itself. Thanks all!
     
    Joelspeanuts likes this.
  13. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    513
    I'm also facing this. For now I manually put to front in the correct order. Probably an editor script could reorder things around to match the prebab. Some "Match scene to prefab GO ordering". As it's for now the first time I face this I won't put time on this, but if anyone needs it for a full project it should be well spent.

    BTW, if it can help anyone, you can multiselect and "move to front/back"

    upload_2022-1-18_13-8-6.png
     
    waishan likes this.
  14. Dahaka444

    Dahaka444

    Joined:
    Jun 15, 2021
    Posts:
    13
    Just wanted to add that in my specific case, I managed to fix this issue by adding a dummy object and deactivating it where the child object was reordered.

    In my nested prefab, I had:
    Child A
    Child B
    Child C (Added to the nested prefab)

    In my scene it became:
    Child A
    Child C
    Child B

    I changed my nested prefab to:
    Child A
    Child B
    DUMMY OBJECT
    Child C
     
  15. guneyozsan

    guneyozsan

    Joined:
    Feb 1, 2012
    Posts:
    99
    I can confirm 2020.3.11f1 has this bug. It is nastier than you can ever think.

    My only workaround is to remove the object and place a fresh one from the prefab. However (!) it is near-impossible to do this in large screen setups with plenty of nested prefabs, configs, overrides,...etc (without wasting countless hours).

    I wouldn't ship even v2020 to LTS without solving this. And the resolution is at v2022 which is not reached LTS and considering not ready for production yet.
     
  16. leon_sabregames

    leon_sabregames

    Joined:
    Aug 26, 2022
    Posts:
    1
    Still happens in unity 2022.1.15f1.
    We reorder objects inside gameobject, but when we UNDO - order is changed to some weird non-original order.
     
  17. tomkail_betterup

    tomkail_betterup

    Joined:
    Nov 17, 2021
    Posts:
    106
    We're seeing this on 2021.3.16f1.
     
  18. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    I solved it in a few not-overly-complex cases by adding a script to the parent which re-orders children based on a value stored in an attached component. Ugly, but it's worked so far.
     
  19. Zaddo

    Zaddo

    Joined:
    May 19, 2012
    Posts:
    78
    This is a horrible bug. I can't believe unity hasn't resolved it yet.
     
    trombonaut likes this.
  20. trombonaut

    trombonaut

    Joined:
    Aug 11, 2021
    Posts:
    10
    Still seems present on 2021.3.18.