Search Unity

Update Hierarchy issue

Discussion in 'Prefabs' started by BAIZOR, Jun 20, 2018.

  1. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    112
    The objects in the variant of my Prefab lost their positions when I change hierarchy in original prefab.

    upload_2018-6-20_14-41-15.png



    There are steps to reproduce:
    1. Create "Head Bot" prefab
    upload_2018-6-20_12-0-16.png

    2. Create "Head Bot Variant 1" prefab from "Head Bot"
    upload_2018-6-20_12-0-55.png

    3. Create an empty GameObject in "Head Bot" and Put legs into GameObject
    upload_2018-6-20_12-3-50.png

    4. Put Right leg and Left leg into GameObject
    upload_2018-6-20_12-5-26.png


    Aaaaaand, what happens with "Head Bot Variant 1" after the last step ???
    The screenshot is in next post.

     
    Last edited: Jun 20, 2018
  2. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    112
    upload_2018-6-20_12-7-34.png
    It looks like something wrong happen...
     
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I think what happens is this:

    When you reparented the right leg and left leg under the new GameObject, their local positions changed. Unity does this when reparenting in order to keep the world positions the same. However, what actually gets stored (and what is shown in the Inspector) is the local positions.

    So the local positions in the base Prefab changed in order to compensate for the different position of their parent.

    However, the positions of the right leg and left leg in the Prefab Variant are overridden, so didn't get updates from the base Prefab. They still got a new Parent GameObject, but didn't get their positions updated to compensate for the different position of the new parent.

    While this is all logically consistent in the system, I can see how it's quite confusing. I'm not sure what can be done about it.

    I'm not completely sure the above is what happened to you; it's hard to say without access to the project, since it depends on the exact positions of the various objects.
     
  4. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    112
    @runevision
    It's a huge problem. Just imagine, you have a deep structured object and few variants of that prefab.
    In some moment you understand that better to change hierarchy in original prefab. If you do that all variants and nested prefabs with overrides could be broken.

    I guess better add to the prefab overriding system ability to change override options for Transform:
    1. override local position from prefab root
    2. override local position
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I understand it can indeed be a big problem.

    We're probably not going to do a whole revamp of how Transforms work to solve this issue; this would have huge implications for a ton of things. Transforms today always store local position (relative to parent), not world position or relative to any other object.

    But we will try to figure out if there could be some other solution to this problem.
     
    BAIZOR likes this.
  6. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    112
    @runevision, I understand. But please, don't forget about the problem. It's really a big one.
     
  7. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    112
    Thanks! In 2018.3 beta it works great! :)
     
  8. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I'm happy to hear that but ... we didn't change anything related to this as far as I know, so I'm a bit stumped why it works better now. :confused: