Hi everyone,
Welcome to the discussion forum for the improved Prefabs features we’re shipping in 2018.3. These features are:
Nesting
Previously, you were forced to choose between creating large monolithic Prefabs, like buildings, or more granular ones, like pieces of furniture, but you couldn’t do both.
Now with support for nested Prefabs, a large building can be made up of many smaller room Prefabs, which in turn can be made up of multiple pieces of furniture Prefabs, and so on.
Prefab Variants
As a default, a Prefab Variant inherits the objects and properties of the Prefab it is a variant of, but at the same time, you have the possibility both to override those properties and to add additional components and GameObjects. This is similar to the concept of inheritance in object-oriented programming.
Prefab Mode
A cornerstone of the new workflows, Prefab Mode enables you to edit Prefabs in isolation.
Being able to edit an entire Prefab Asset without having to instantiate it in the scene or edit an existing instance means you can avoid mistakes related to accidentally applying overrides in the scene that shouldn’t have been applied. Having editing of instances and asset as separate things lets you make your changes with confidence.
You can find more detailed information about these features in the manual.
For information about upgrading an existing project to 2018.3 please have a look at the upgrade guide.
___________
Here are some of the frequently asked questions.
How do nested Prefabs and Prefab Variants impact performance?
Performance at runtime: Prefabs are baked out as part of building players. Nested Prefabs, Variants, and even Prefab in general are not concepts that exist in built players. This means there is no CPU time spent on resolving nesting and applying overridden property values, since all content is “pre-nested” in the built process. It does mean that the data for GameObjects and components take up disk space and memory separately for each instance, since they exist as completely separate copies. This is all the same as in previous versions of Unity; no change there.
Performance in the editor: Whenever a Prefab Asset is changed, it is re-imported, and all Prefabs that has it as a nested Prefab or base Prefab are imported as well. This means that the time it takes to save a Prefab after altering it scales with the number and sizes of other Prefabs that contain instances of it.
Can we edit Prefabs directly in the Project Browser?
Editing the Prefab root in the Project Browser is supported in Unity 2018.4 and later.
Can we use Prefab Mode but edit the Prefab Asset in context of the current scene instead of in isolation?
This feature, called Prefab Mode in Context, is available in Unity 2020.1 and later.
Why is the root of a Prefab in Prefab Mode not blue and not using the Prefab icon?
Prefab assets in the Project Browser and Prefab instances in the Hierarchy use the Prefab icon. Prefab instances use blue text too. In Prefab Mode, you are not seeing a Prefab instance, but rather the contents (such as regular GameObjects) that are inside a Prefab Asset. See the documentation for more information.
Can we get the ability to treat Prefabs as “black boxes” or “encapsulated” where by default properties can’t be edited (overridden) on instances of the Prefab?
There’s a simple version of this where no properties can be overridden on instances (except root Transform and a few other basic ones), and a more complex version of this, where it would be possible to expose specific properties in a Prefab Asset so they can be overridden on instances too. Both are things we have been looking into, and would like to do for future releases.
Can we get a tool to see which Prefab Variants inherit from a given Prefab, or even the entire inheritance graph?
This is something we might explore in a future release. (It’s a bit related to being able to see asset dependencies in Unity in general, which there is also not any built-in tooling for.) For savvy users who want a solution in the shorter term, there is sufficient API exposed to be able to implement such tooling, in that you can see which base Prefab a given Prefab Variant inherits from.
Can we get an indication that a Prefab instance has any overrides directly visible in the Hierarchy window or Inspector without having to open the Overrides drop-down and check?
This is something we’d like to do for a future release. The main thing that kept us from doing it in the initial release is that it’s not so cheap to check this that we can do it constantly, and we don’t have a dirty tracking system in place for Prefab instances that we could use to cache the information and know when to invalidate the cache.
Which callbacks related to Prefabs and Stages can I hook into from scripting?
Additionally there are these in the experimental namespace UnityEditor.Experimental.SceneManagement
.
Note that this is not guaranteed to work in future versions of Unity.
- PrefabStage.prefabStageOpened
- PrefabStage.prefabStageClosing
- PrefabStage.prefabSaving
- PrefabStage.prefabSaved
Why do I get dialogs titled “Cannot restructure Prefab instance” / what happened with disconnecting Prefabs?
Prior to Unity 2018.3 you could perform operations on a Prefab instance that would disconnect it from its Prefab Asset, such as deleting or reparenting GameObjects. Once disconnected, the Prefab instance would no longer receive updates from the Prefab Asset. Support for disconnecting Prefab instances has been discontinued in Unity 2018.3 because it’s not compatible with the new Prefab features. Attempting to delete, reparent or reorder GameObjects in a Prefab instance will bring up a dialog saying it’s not possible and suggesting making the edits to the Prefab Asset itself in Prefab mode, or unpacking the Prefab.
Disconnecting Prefab instances is incompatible with new Prefab features such as nested Prefabs and Prefab Variants because disconnected Prefabs don’t have a clear definition of what belongs and doesn’t belong to the same Prefab instance. It’s necessary to have clear definitions of that when also supporting nested Prefabs and Variants in order for all the logic that manages the various Prefab relationships to work.
Replacement workflows are to either make edits to the Prefab Asset directly in Prefab Mode, or unpacking the Prefab instance (which makes it into regular GameObjects with no information about what Prefab they used to be part of). The root GameObject of what used to be the Prefab instance can be dragged onto the Prefab Asset to replace the Prefab, which is equivalent to how disconnected Prefabs could previously be reconnected again.