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:
    122
    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:
    122
    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

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,686
    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:
    122
    I just filed a bug report for it. Thank you.
     
    runevision likes this.
  5. Dunk86

    Dunk86

    Joined:
    May 10, 2015
    Posts:
    51
    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:
    725
    @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

    Unity Technologies

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

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    122
    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:
    220
    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
  10. sp-LeventeLajtai

    sp-LeventeLajtai

    Joined:
    Jul 11, 2019
    Posts:
    3
    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.
     
    gresolio, Dunk86 and Bill-Sansky like this.
  11. Bill-Sansky

    Bill-Sansky

    Joined:
    Oct 2, 2016
    Posts:
    61
    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!
     
    kingofthestack and Horothenic like this.
unityunity