Search Unity

Could someone clarify how prefab overrides work with nesting?

Discussion in 'Prefabs' started by bac9-flcl, Dec 14, 2018.

  1. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    Let's say I have a prefab in my scene and change some values on its components. These new values are now considered overrides on the prefab instance and are saved inside the scene. I can inspect them and apply them to prefab asset.

    Now, let's say that prefab contains other prefabs inside - for example, in-scene prefab instance is a root of a UI hierarchy and inside of it, there are two instances of a window prefab. I can inspect and change any settings on that nested instance as well, and they would be correctly saved. The window prefab instances nested under the UI root prefab can in turn have more instances (of prefabs like buttons) nested under them, which are also editable from the scene, with any edits correctly being saved.

    Which brings us to nested overrides. Applying overrides to a single-level traditional prefab is a simple concept to understand - just save any differences to asset linked to a given instance. But how does registration and application of overrides for nested instances work? Are overrides only ever registered for the topmost instance level, to remove ambiguity of possibly conflicting edits to nested instances? Or is ambiguity of nested override application resolved in some other way? And if any changes to nested instances are not saved to overrides and can't be applied without going one level deeper, how are they serialized in the scene?
     
    Last edited: Dec 14, 2018
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    overrides are only ever on the outermost prefab for exactly the reason you mention.
     
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
  4. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    429
    Let's say I have prefab Table which has nested prefab Vase.
    I have changed many properties on several components of Vase.
    And I want to apply those changes to Prefab Vase.
    Why there is no single menu command which applies all changes of Vase nested prefab to Vase prefab asset?
    Currently, I need to manually iterate for each game object and each component on it in vase nested prefab and click on each component and click apply to Vase prefab. It seems like so many not necessary things I need to do and it is error-prone!
    Same goes for reverting!

    I tried to right-click top most inspector of vase nested prefab and there is no menu item like "Modified prefab" (like on modified component). And there is now drop down buttons like apply all overrides. There should be context menu on game object inspector to apply all changes of nested prefab to its prefab asset at once. Same goes for reverting.

    Is there a reason to not implement this?
    And are there any plans to do that?

    Because it seems like a significant flow to me.
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    It's not currently in our plans to do this.

    Applying directly to nested Prefabs is a bit more complicated than it might seem. It actually doesn't just modify the values on the Prefab that's being applied to (the Vase in this case); it also clears any overrides there might be of those same properties on all Prefabs further out than the one applied to (so any overrides to the same properties in the Vase there might be inside the Table Prefab, in this case). This is necessary so that the value of the properties in the scene don't suddenly change after having been applied to the nested Prefab, but it's not intuitive that this happens and why, without thinking quite a bit about it.

    So it's best to use the functionality of applying directly to nested Prefabs sparingly, and think about the consequences of each apply, and we don't encourage mass-using it, due to high risk of unforeseen consequences.

    Another reason was that back in beta of the nested Prefabs feature when we tried having UI for applying all properties to a nested Prefab and usability tested it, we found many people were scared off of the whole Prefab feature-set in general because this UI that made things more complex and harder to understand the consequences of. Having observed that, we prioritized getting the simpler use cases covered and shipped.

    In general, we highly encourage using Prefab Mode if you are going to make many edits to a Prefab and know you want them to be on the Prefab Asset, and not just on the one instance, as it has much lower risk of unforeseen consequences than editing via an instance and then applying has.

    You can revert all properties at once via the Overrides dropdown.
     
    Prodigga and TextusGames like this.
  6. jimmyjamesbond

    jimmyjamesbond

    Joined:
    Mar 17, 2015
    Posts:
    19
    Working in prefab mode is almost unusable when using a nested prefab in context of another hierarchy. Editing the final product and then having the ability to apply those changes in mass is needed badly. I have to select each change and apply it and re-open the overrides menu for the next. I've been doing that for 30 minutes to apply one prefab as I have 50+ changes.