Search Unity

Deleting, Moving or Reordering objects

Discussion in 'Prefabs' started by Tomer-Barkan, Nov 19, 2018.

  1. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    When I try to delete an object within a prefab, or move it, I get the good old message that this will break the prefab connection. Is this temporary in the beta, or something that is planned for good? Will we be able to make a prefab variant that removes parts of the prefab? If not - why not - technical limitation or design choice?

    Especially problematic is the fact that I can't add non-prefab objects between the prefab's children. This is essential when constructing UI prefabs, since the order of children plays such a vital role.
     
    Last edited: Nov 19, 2018
  2. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    I meant to post this in the improved prefabs forum and posted in 2018.3 beta by mistake. I can't find a way to move or delete it, so would appreciate if an admin can move it there. Thanks!
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    @LeonhardP are u guys still collecting feedback for the new prefab workflows or is it too late ? :)
     
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Feedback is always welcome. Just keep in mind that bigger changes will take their time.
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I assume you mean the 'Cannot restructure Prefab Instance' dialog? It's different from the old one about breaking the Prefab connection. Breaking the connection is no longer possible.

    It's a technical limitation / something that wasn't implemented. Note that for the improved Prefabs feature we didn't change what type of overrides it's possible to have on Prefab instances. It wasn't possible to delete GameObjects as overrides before (that's why it would break the Prefab connection) and we didn't change that, since our focus was on nested Prefabs, Prefab Variants and Prefab Mode, and we tried not to have too much scope creep so we'd never be done.
     
  6. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    Thanks for the update @runevision, however, I believe there is a slight, but important, regression compared to previous versions.

    In previous versions we could insert a game object inside a prefab in between children, without having it break the prefab connection:

    upload_2018-11-22_14-41-21.png

    in 2018.3, if I edit a prefab variant and try to add a new object in between the original prefab's children, then it won't let me:

    upload_2018-11-22_14-42-51.png

    This is kinda major because positioning in UI affects the order of appearance in layouts and also which element is behind which other. I hope maybe this is just a small bug that can easily be fixed if you've based it on the previous system that did allow this.


    I totally understand that, but please consider changing this in future versions. Again, since Unity's UI is so dependent on positioning.
     
    Last edited: Nov 22, 2018
    leni8ec and Rycons like this.
  7. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    That's true but it resulted in undefined behaviour since we don't actually have any code that handles merging of a reordered or otherwise modified list on an instance when the list has also been reordered or modified on the Asset as well. (There's also no trivial and completely reliable way to do this.) In 2018.3 we chose to be more conservative to avoid undefined behaviour and the bugs that could result from it. (That said, we still have some bugs regarding this and we're looking into those.)

    I forgot to say in my previous reply that our recommended way to handle UI elements in a variant that need to be inserted in between elements from its base is to have a placeholder element in the base (that fully stretches to the parent's size) and if needed insert element as children to that placeholder in the Variant. The placeholder GameObject can be deactivated in the base. This also gives fully predictable behavior where even if you're editing the order of the elements in the base, you can easily foresee how it affects the Variant with its extra elements because you're explicitly controlling it via the placeholder.
     
    akareactor, Ultroman and Tomer-Barkan like this.
  8. Meatloaf4

    Meatloaf4

    Joined:
    Jul 30, 2013
    Posts:
    183
    Just ran into the issue of reordering and unity UI.

    While I really appreciate you guys being conservative as to ship the product, this seams to be pretty imperative if were to build out UI's using the new nested prefab system.

    Not sure I quite understood your example workaround @runevision. Mind showing some images, or any supplementary resources to show what you mean.

    Thanks in advance!
     
  9. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    You want to insert an extra child somewhere among the childen of an existing Prefab.

    Open that Prefab and add a placeholder child GameObject in the position where you want to be able to add children. Set it to stretch to the full extent of its parent, like in the image. You can deactivate the GameObject too so it has no effect.

    Then back where you wanted to insert a child, add it as a child to the placeholder, so it becomes an added GameObject override. Activate the placeholder GameObject as an override too.

    If you're using auto layout (like layout groups) you may need to add a VerticalLayoutGroup to the placeholder as well that wraps whatever content you add as a child under it.
     

    Attached Files:

  10. keevee

    keevee

    Joined:
    May 22, 2015
    Posts:
    2
    The problem with this workflow is that it makes it very difficult to work on a prefab structure as a whole.
    As an example, for levels in a game I am building, I have a prefab that holds the level as a whole.
    Within this prefab are 3 different main pieces: The level geometry itself, pickups that exist throughout the level, and special interactive pieces in the level.

    For collaboration, we want to be able to have one person edit the geometry, another edit the pickups, another edit the interactive items, and not have merge conflicts.

    To do this, the level prefab has two nested prefabs: one containing all pickups, and one containing all special interactive items.

    The problem is that if I want to delete a pickup or special item, I have to go into that prefab just to delete it. This makes the workflow really cumbersome. If I want to delete quite a few items but figuring out what to delete depends on seeing the level geometry, then I have to go back and forth constantly.
     
  11. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Have you had a look at this?
    https://forum.unity.com/threads/prefab-mode-in-context-now-in-2020-1-beta.848869/
     
  12. keevee

    keevee

    Joined:
    May 22, 2015
    Posts:
    2
    Woah! I was not aware this was in the works. I'm really looking forward to this. Although I will still have to enter another mode instead of freely moving things anywhere in the hierarchy, this seems like a massive improvement.

    PS: I see an auto-save tickbox, THANK YOU!!! I noticed right away in the existing prefab editing system that any edits would automatically be applied, and being able to control that is going to be a life saver. I'll have to take a look at what other features are in the work for the 2020 editor. Thanks for pointing this out!
     
  13. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    The Auto Save toggle has been there since 2018.3. ;)
     
  14. Baldor

    Baldor

    Joined:
    Jul 24, 2018
    Posts:
    5
    Simply right click on the Prefab in the SceneHierarchy choose prefab--->unpack and now you are able to change whatever you want on the Prefab. If you are done drag it to the ProjectHierarchy and it automaticly creates a Prefab of your changed Object.
     
  15. HugoZink

    HugoZink

    Joined:
    Mar 4, 2018
    Posts:
    13
    Can I ask why we are allowed to use "Set as last sibling" just fine in Unity 2018+, but we can't drag gameobjects to reorder them and achieve literally the same result?

    To be clear, why can I do this without breaking the prefab instance:
    upload_2020-12-13_3-0-52.png
    But I'm not allowed to drag the gameobjects around to set them as last sibling, like this?
    upload_2020-12-13_3-2-39.png

    This seems extremely counter-intuitive. These two methods did the same thing in Unity 2017, but now one of them gives me an error popup, for apparently no reason.
     
  16. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @HugoZink

    That is a bug and we actually noticed ourselves last week, it has been fixed and will ship in a future release