Search Unity

GameObjects not in same order as in Prefab?

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

  1. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    I don't know how it happens, but as I make changes, the order of GameObjects in the hierarchy become different to what they are in the Prefab. And then I cannot arrange them back because it pops up to say I need to "Open Prefab" to make changes to Prefab children.

    What I have is 2 levels deep prefab.
    Scene has Prefab A
    Prefab A is a variant of Prefab B

    When looking at Prefab A the order of GameObjects defined in Prefab B is not the same as in Prefab B.

    This has happened to me twice now. Last time I recreated Prefab A to fix it. I'm not sure if this first happened in 2018.3.0b6 or b7, but right now I am in b7.

    It is strange because I though you couldn't re-order children defined in a prefab, but here the prefab's children are re-ordered.

    It may be caused by me changing the order of children in Prefab B and then Prefab A got confused or something. Prefab A also adds new children and somehow they got in-between the ones defined in Prefab B.
     
  2. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    OK, one thing that might cause problems I've found is:

    Suppose Prefab B children list is:
    • Bchild1
    • Bchild2
    • Bchild3
    Prefab A is created as a variant of Prefab B and starts as:
    • Bchild1
    • Bchild2
    • Bchild3
    Then I add 2 children to Prefab A:
    • Bchild1
    • Bchild2
    • Bchild3
    • Achild1
    • Achild2
    Then, I decide Prefab B needs a new child, so Prefab B becomes
    • Bchild1
    • Bchild2
    • Bchild3
    • Bchild4 < added
    When I go back to Prefab A, I see this:
    • Bchild1
    • Bchild2
    • Bchild3
    • Achild1
    • Achild2
    • Bchild4 < added to end??
    I would expect Bchild4 to be added between Bchild3 and Achild1 like this:
    • Bchild1
    • Bchild2
    • Bchild3
    • Bchild4 < it should be added here
    • Achild1
    • Achild2
    Instead it is added at the end, making all of A's new children being between B's children. And if I want to move Bchild4 back up to where I think it should be, I can't do it directly. I have to drag Achild2 and Achild1 down one by one.

    I think this may be one of the causes of the problem I noted in my first post.

    EDIT: Then, after more re-arranging in Prefab B, Bchild4 magically moves to where it should be. I think this needs to be a bit more robust.
     
    Last edited: Oct 28, 2018
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    This is a bug. A Prefab's own children should always come before children that are added to an instance of it. We would appreciate if you could file a bug report. Thanks!
     
  4. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    I just filed a bug report for it. Thank you.
     
    runevision likes this.
  5. Dunk86

    Dunk86

    Joined:
    May 10, 2015
    Posts:
    53
    I'm having this issue too but you didn't link to the bug report and I can't find it on google.
    I wanted to place a 'dummy' object as the first child of my UI prefab, so I could work-around the "Cannot restructure Prefab instance" limitation. Unfortunately, the 'first' element actually appears at the end if your instance has been touched already - which means I have to re-create the entire instance again :(

    Here's a gif of the issue:
    BugGif.gif

    P.S. I'm running Unity 2018.3.5f1 so maybe it's been fixed already?
    EDIT: I tried 2018.3.9f1 and get the same behaviour
     
    Last edited: Mar 19, 2019
  6. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @runevision I can confirm this is still broken in 2019.1.5. Basically, as @Dunk86 reported, this bug makes it impossible to effectively reorder a prefab's children, as the children's order within a prefab instance (in the production scene) doesn't match the children's order in the asset prefab. With no way to fix it besides nuking the prefab instance and re-instantiating it. Which is FAR from ideal.

    Edit:
    Here are more details about what I did:

    - I went to the prefab scene (select instance, click Open button), deleted the child that appeared in the wrong order.
    - Went back to the production scene, the child was gone from the prefab instance (as expected)
    - Went back to the prefab scene, recreated a new child in the proper order.
    - Went back to the production scene: the new child was there, but still at the end of the children (NOT where it was in the prefab scene).

    I tried it several times (even using copy/paste on the child) to no avail.

    The issue only went away after I enforced all the overrides on the prefab instance (although none seemed to be related to said child). After that, the child I recreated (once again) in the prefab scene finally appeared at the correct hierarchical position in the prefab instance.
     
    Last edited: Jun 14, 2019
  7. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    What are the bug case numbers?
     
  8. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    168
    Mine is:
    Case 1095995

    BTW I have run into behavior like Dunk86 reported too, but was able to workaround it somehow (can't remember specifics).
     
    runevision likes this.
  9. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    The bug has been there since the new prefab system was implemented and still not fixed in 2019.2.2. I have a window like prefab something like

    Window(prefabt)
    - background image
    - caption
    - contents

    I use this prefab a lot and in some gameobjects where the prefab is placed, the bug makes the background image the last sibling in the transform and hides everything behind. And I can't change the transform order since....it's prefab.


    Here's the screenshot
    upload_2019-8-27_23-22-48.png upload_2019-8-27_23-23-2.png

    Notice how the sibling orders are different(messed up) from the original prefab(Window).
     
    Last edited: Aug 27, 2019
    WookieWookie likes this.
  10. sp-LeventeLajtai

    sp-LeventeLajtai

    Joined:
    Jul 11, 2019
    Posts:
    10
    Maybe this issue is related to the 2 "impossible" (undesired) situations described in this article? The solution there is to manually remove the
    m_rootOrder
    elements from the prefab. Far from ideal, but at least there is a solution.
     
  11. Shrubokrant

    Shrubokrant

    Joined:
    Oct 2, 2016
    Posts:
    80
    Wow, that's a detailed article :eek:
    On the subject, you can still use the "Set as last sibling / Set as first sibling" that's in the menu "GameObject" to not get the popup message. (I use the reordering feature of my MonKey plugin for that myself)
    This is inconsistent to me: Unity tells you it doesn't allow to reorder objects in prefab variants, but actually... it does!
     
  12. GEL-tech

    GEL-tech

    Joined:
    Jul 5, 2017
    Posts:
    3
    Still happens in 2019.3.3f1

    100% reproducible from a new project, any time you add child objects to a prefab instance in a scene.
    Bug report #1224509.
     
    contactjakemb and chanon81 like this.
  13. HIroLionBld

    HIroLionBld

    Joined:
    Sep 20, 2019
    Posts:
    9
    Having the same problem, this bug is annoying because some of the UI elements depends on the order of the children in the prefab
     
    koriball and contactjakemb like this.
  14. contactjakemb

    contactjakemb

    Joined:
    May 27, 2019
    Posts:
    3
  15. pocketpair

    pocketpair

    Joined:
    Jul 7, 2015
    Posts:
    72
    This is the serious issue and easy reproduced. Please help me.


    This is one of the workarounds but bothering to attach all of gameobjects and assign indices.
     
  16. WookieWookie

    WookieWookie

    Joined:
    Mar 10, 2014
    Posts:
    35
    @runevision We are in 2019.2.7f1 and the prefab system is ruining my life in the UI.

    Thanks to a decision made early on to make entire menus into prefabs, these problems are rampant:
    1. Prefab overrides are auto-generated constantly by the (dumb) floating point layout system. I think I have a ratio of about 1 desired override per 100.
    2. Edits to prefabs do not always propagate to variants or nested instances "intact". Edits often result in completely random results up the chain, with UI jumping out into outer space in Z or other crazy results.
    3. Prefabs randomly reorder themselves, and then will refuse to allow any reorder. The only way to fix this is nest the prefab inside a "holder" gameobject.
    Is there a patch we can pull down that addresses these issues?

    FWIW, the override system should not even exist. Users asked for many years for nested prefabs, and nesting is all we needed. This system is complete overkill, and it sets up the users to fail completely due to the temptation to use overrides and variants. Neither has proven to be of value, after 9 months on a project building screens daily. And now I'm stuck with it all.
     
    sp-LeventeLajtai and jiraphatK like this.
  17. Lavanda49GS

    Lavanda49GS

    Joined:
    Jul 19, 2019
    Posts:
    15
    Confirm. Bug still present in unity 2019.3.0f6
    Cmn, fix it someone! Or just make biggest deal in your life and, at least, OPEN source of unity for all!
     
    Vedran_M likes this.
  18. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Still bugged in 2019.4.5 LTS version...
     
    Last edited: Sep 17, 2020
    unnanego and Vedran_M like this.
  19. SangOk1994

    SangOk1994

    Joined:
    Jun 11, 2020
    Posts:
    2
    I found something.
    upload_2020-8-7_12-6-12.png

    It can change order in hierachy.
     
  20. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    Wow, I want that version! :D
     
  21. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    I don't have those buttons but these ones are enough sometimes:

     
    Last edited: Nov 10, 2020
  22. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    That is actually the Context menu of a RectTransform, and refers to the rendering order of UI objects, which is something completely different.
     
    Last edited: Aug 24, 2020
  23. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    That is extremely interesting, because it does actually work (haven't tested for side-effects, though, for example when re-ordering FBX children in a Prefab-Variant of a model)! While the Editor forbids you to do exactly that!

    => @Unity @runevision: So it IS in fact possible to re-order objects within a Prefab instance. Is there a problem with this "trick"? Or to rephrase: So why then would you prevent the user from re-ordering Prefab-Instance children (or for example children of Prefab-Variants of models), if it's obviously implemented and working?

    EDIT: Also, here is another example:
    Screenshot (52).png
    This was auto-converted from a 2017.4 project (=before the new prefab model): An instance of a prefab, which has another prefab as one of its children - specifically placed in the hierarchy (=2nd child of three children). In Unity 2019.4 it is NOT possible to do this (except when using @Kamyker 's workaround)! - and yet: This screenshot is from a 2019.4 project, auto-upgraded from 2017.4, and it works exactly as it should (as in, the "forbidden" UI element "Entry_Toggle (3)" even renders before "InputField", and after "Text").
     
    Last edited: Aug 24, 2020
  24. Mawkey

    Mawkey

    Joined:
    Apr 15, 2018
    Posts:
    15
    This needs to be fixed, but I can confirm that using GameObject > Set As First Sibling works though.

    @Kamyker Thanks for pointing that out.
     
    intsoftgames likes this.
  25. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Yes, it's not reliable and robust. In general there's various known issues related to child ordering inside Prefabs and it's being looked at. We will prioritize robustness and consistency first, but also see if it's viable to add more flexibility.
     
  26. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hi,

    Almost 3 months since last message and the bug still exist which is really, really annoying when it comes to UI. It's like you have to toss a coin and prey it will fall on the right side to have your UI displayed as intended.
     
    chanon81 and sp-LeventeLajtai like this.
  27. Lavanda49GS

    Lavanda49GS

    Joined:
    Jul 19, 2019
    Posts:
    15
    Hi, thats why practice of proprietary software is soooo bad... Unity are unable to handle their engine and wont to give this abillity to other, which sounds like child behaviour LOL. Make look at Godot engine, which absolutely free and open-source.
     
  28. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Just to give an update, we are very close to a solution to this problem. The problem is very complex and development has been going on for quite some time.

    Unfortunately the problem is so complex and the code changes quite significant that is considered a risky change, so a backport to 2020 is not likely to happen but we will be evaluating that once the work is complete.
     
    koriball, ROBYER1, Wolfram and 2 others like this.
  29. evyatron

    evyatron

    Joined:
    Jul 20, 2014
    Posts:
    132
    I ran into another hierarchy issue - whereby simply having prefabs in my scene hierarchy causes the hierarchy order to scramble when reopening the scene.

    Case 1313739.

    I was wondering whether this is the same issue as the one in this thread?
     
  30. MorpheusZG

    MorpheusZG

    Joined:
    Jan 6, 2020
    Posts:
    18
    Where can I track the status of this issue? This is quite severe.
     
  31. icefallgames

    icefallgames

    Joined:
    Dec 6, 2014
    Posts:
    75
    Wow, just ran into this. What a terrible bug. Making it a nightmare to fix some of our UI issues.
     
  32. contactjakemb

    contactjakemb

    Joined:
    May 27, 2019
    Posts:
    3
    I found the "Set as last sibling (Ctrl + -) / Set as first sibling (Ctrl + =)" solution mentioned by others to be the better workaround. Just make sure Unity has saved your changes! If you just update the order of game objects, Unity does not notice the change and there is no pop up to say the "Scene(s) has been modified", "Do you want to save the changes you made..."
     
    Danielpunct likes this.
  33. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    I cannot confirm this problem in 2019.4.17f1, the Scene gets correctly dirtied (=marked with a '*'), and the same is true if you change the order within a prefab instead of the scene.
    Which Unity version are you using?
     
  34. contactjakemb

    contactjakemb

    Joined:
    May 27, 2019
    Posts:
    3
    2020.2.1f1
     
  35. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    Can confirm in both 2020.2.1f1 and 2020.2.6f1, so it indeed looks like a regression.
    Bugged as 1317759.
     
    ROBYER1 and contactjakemb like this.
  36. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    261
    contactjakemb likes this.
  37. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    Can confirm 2021.1.7b also has this issue. Updates to tranform order in parent prefabs doesnt properagate to child prefabs and things end up in the wrong order with no way to change them.

    Edit: You can use Set as first and last sibling to change the order and that for no reason doesnt mark it as an override. But chaning transform order in the parent of a prefab with 100 children means manually doing that for each child, for every transform, until they are in the right order again...
     
    ROBYER1 likes this.
  38. user10398483

    user10398483

    Joined:
    Feb 5, 2021
    Posts:
    3
    It's been 2 months, any update?
     
  39. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    5 months since unity said they were very close to a fix.
    Would be nice to get an update as we are stil having to manually edit meta files to fix it.
     
  40. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @SevenPointRed

    We ran into some issues with the Undo system which required a major refactoring and minor change in behavior of the Undo system. It complicated and takes time.
     
    koriball and Wolfram like this.
  41. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    Not the undoing, the original issue was the prefab order being wrong if you add gameobjects to a parent prefab.
     
  42. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    This also still happens in the 2021.2 alpha
    Seems worrying as the original bug was posted in Oct 2018
     
  43. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    Just to give more info, this is a screenshot from a fresh project in 2021.2

    upload_2021-5-19_16-50-54.png
    Steps:
    Create "Parent"
    Add A to Parent
    Add B to Parent
    Make Parent a Prefab
    Add C to Parent
    Create Prefab varient from Parent, called Child
    Open Child
    Add Child_A
    Add Child_B
    Open Parent
    Add D
    Open Child
    BUG: D is now listed after Child_A and Child_B
    Add Child_C
    Open Parent
    Add E
    Open Child
    BUG: E is now randomly added half way through the hierarchy, not even in the correct order as the parent, so you cant move it at all.
    Screenshot..

    Child should just list A,B,C,D,E then Child_A, Child_B, Child_C

    This is very fustrating when working with UI as all the rendering order gets broken and you have to manally edit the meta files for EVERY transfrom or use the "set as last child", all the while making sure you do it in the right order.
     
  44. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @SevenPointRed

    I know what you are talking about :)

    But like I said we ran into issues with Undo related to fixing the order of the GameObject. So in order to ship the fix for the order of the GameObject we also have to fix the undo issue, otherwise we would get bug reports about crashes when trying to undo rearranging the GameObject.

    We have to make sure what we ship is solid and does not generate more bug reports, especially when we find the bugs during our own testing.
     
    ROBYER1 likes this.
  45. user10398483

    user10398483

    Joined:
    Feb 5, 2021
    Posts:
    3
    @SteenLund Will Unity implement default Web View that supports iOS/Android/Windows/Mac etc just like Unity?
     
  46. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    @SteenLund, is this fix going to get merged into 2021.1? I'm encountering it right now in 2021.1.24.
     
  47. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @angrypenguin The fix landed in 2022.1. Unfortunately it is a rather large change and it has dependency on a large fix and refactoring of the undo system so we can't backport it to earlier versions of the editor
     
    ROBYER1 likes this.
  48. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    2022? Do you mean 2021.2?

    Will the currently active LTS branches at least get the fix?
     
  49. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    No, I meant 22.1.

    No we can't backport it. Too much has changed in 22.1 and there are too many dependencies on these changes, backporting it would be a massive risk to 21LTS
     
  50. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Any suggested workarounds for projects where upgrading to access the fix isn't feasible?