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:
    76
    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:
    76
    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,558
    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:
    76
    I just filed a bug report for it. Thank you.
     
    runevision likes this.
  5. Dunk86

    Dunk86

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