Search Unity

One of the top requested additions to Unity is the ability to nest Prefabs. But we know a lot of you need many more changes to the Prefab workflows than that. Therefore, we’re improving the whole system with focus on reusability, control & safety. This is the first in a series of blog posts explaining the upcoming changes. If you haven’t done so already during yesterday’s Unite Berlin keynote, get the preview Unity build with the new Prefab system here.

Let’s start by recapping the basics of what Prefabs are in Unity. Fundamentally, a Prefab Asset is like a template of a GameObject and its children. You can use instances of a Prefab Asset to create many copies of a GameObject throughout your Scenes. If the Prefab Asset is changed, all the Prefab instances are automatically updated accordingly.

We talked to a wide range of indie and AAA studios to dig deep into how you all work with Prefabs at the moment. An issue we found was that when you wanted to edit a Prefab Asset, you had to drag it to an open Scene in the Hierarchy to modify it, apply the changes and then remember to delete it again. Another big issue was the Apply button for Prefab instances in the Inspector. With this button, you could accidentally apply changes to the Prefab Asset that you had no good way of getting an overview of.

To address these issues we have introduced a range of new features. We have implemented a backwards compatible Prefab backend that now supports nesting and inheritance. We have improved the visualization of property and object overrides for Prefab instances, and added the ability to apply overrides on multiple levels of granularity: per property, per Component/GameObject, or, as before, the entire Prefab instance. Lastly, we have added Prefab Mode to be able to edit a Prefab Asset in isolation.

Prefab Mode

Prefab Mode represents a fundamental change when working with Prefabs. It lets you decide whether you want to make changes to a Prefab instance or make changes directly to a Prefab Asset.

Prefab Mode gives you a more controlled Prefab Asset editing session because you can perform all changes to the Prefab Asset, including structural changes, without receiving dialogs asking you to break the connection to the Prefab. With Prefab Mode, you no longer need to make temporary changes to a Prefab instance with the sole purpose of applying these changes to the Asset later (with the possible side effect of applying other previous overrides that were meant to be kept as overrides). So we recommend you use Prefab Mode for Prefab Asset changes, and only make overrides on Prefab instances when needed. Note that we have also improved the Apply workflow tremendously. More information on this workflow in an upcoming blog post!

Prefab Mode takes over the Hierarchy and Scene View to show the Prefab Asset in isolation. You can recognize this mode by the new headers in the Hierarchy and Scene View. Also note that the Prefab Mode background color can be customized in the Preferences.

When entering Prefab Mode from the Scene, for example by clicking the arrow marked by the red circle, the Hierarchy shows the Prefab header and the Scene View shows the breadcrumbs header (marked by the red boxes).

You can enter Prefab Mode by doing one of the following:

  • Double-clicking the Prefab in the Project window.
  • Clicking the new arrow button in the Hierarchy window next to the root GameObject of the Prefab instance.
  • Clicking the Open button in the Inspector for the root GameObject of the Prefab Asset or Prefab instance.

Working with Prefab Assets

To enable Prefab nesting, we had to make technical changes to the Prefab backend. So, technically, Prefabs are now imported Assets. This means you can no longer edit Prefab GameObjects in the Project window. Compared to the old workflow of editing directly in the Project window, Prefab Mode lets you edit objects at any depth, and see what you’re doing in the Scene view too.

Working with Prefab instances

Another consequence of providing Prefab nesting is that you can no longer disconnect a Prefab instance to make structural changes to that instance. This includes deleting GameObjects, reparenting GameObjects, or replacing a Transform with a RectTransform and vice versa. You can now do all of this in Prefab Mode. Alternatively, you can now unpack a Prefab instance if you want to entirely remove its link to its Prefab Asset and thus restructure the resulting plain GameObjects as you please.

Prefab Stage

We have introduced the term ‘stage’ in the Editor as a concept for a set of GameObjects isolated from other GameObjects. When you are in Prefab Mode, the breadcrumbs at the top of the Scene view each represent a different stage. Each stage is like a separate ‘world’. By default, we have the Main Stage, which is the stage where all your Scenes are (the Scenes you have loaded and can see in the Hierarchy). When opening a Prefab in Prefab Mode, we create a Prefab Stage for the contents of the Prefab. We do not unload the Main Stage GameObjects when a Prefab Stage is opened, and this means you can still see them in the Game view.

The Scene view and Hierarchy always show the current stage, which is the one corresponding to the rightmost breadcrumb. To go back to the Main Stage with your Scenes, either click the ‘Scenes’ button in the breadcrumbs of the Scene view or the Back arrow button in the Hierarchy.

To see the new workflows in action check out the video below:

To try the new Prefab features, download the preview build from our Prefab page. Also check out our dedicated forum for Improved Prefabs for more information, questions and feedback.

Stay tuned for upcoming blog posts with more in depth information about other parts of the improved Prefab workflows.

Improved Prefabs at Unite Berlin: Live Today

If you want to see the improved prefab workflows in action, we highly recommend tuning into the live stream from Unite Berlin today on YouTube or Twitch. Starting from 5pm Berlin time, you can catch Improved Prefab Workflow with Ciro Continisio. After that, Rune Skovbo Jacobsen and Steen Lund will help you better understand the pros and cons of our implementation decisions in their Technical Deep Dive into the New Prefab System (6pm). We’ll work on editing the talks later and upload them to our YouTube channel within a month after the conference.

Dejar una respuesta

Puede utilizar estas etiquetas y atributos HTML: <a href=""> <b> <code> <pre>

  1. What beta release of 2018.2 will include prefab workflows? if any? I have been using the preview build to play with prefabs, but I dont see shadergraph in package manager.. I’m really excited to get a build with all the new features! going to be amazing!!

    thank you so much!
    Brian Acker

    1. Improved prefab workflows are currently slated for 2018.3. What’s available now is a custom preview build.

  2. This is so amazing, like my heart goes out to all the people that made this possible!! By the way, I know the preview build is out, but do we know yet what the first Unity version will have this built-in?

  3. Mads Nyholm, thanks! And thanks for sharing your great posts every week!

  4. Great Feature and implementation !
    But… When adding an object in the hierarchy of an FBX file, prefab already created with this fbx doesn’t automaticly updated. Need to break and make the prefab again as before. FBX should be prefab too from start
    (just tried with the preview release)

    1. Could you please ask you question in the forum
      https://forum.unity.com/forums/improved-prefabs.158/

      To me is sounds like what you are trying to do can be achieved with a Variant.

    2. You need to create a Variant of the model first: Right click on your model in the Project Browser and select Create -> Prefab Variant. This will generate a Prefab Variant next to your model. Now use this variant in your scenes to have it automatically update when you change the source model in your DCC while keeping your overrides to the model.

  5. Finally !!!

    This is the strict minimum of what we needed for prefabs, but that is cool that you did it. I hope that everything will work without any issues.

  6. If I instantiate the same prefab multiple times in the scene, how is the serialization? Right now same prefabs take a lot of storage in the scene. Will that also be improved?

    1. There are no changes to how scenes are serialized for players.

  7. We can no longer edit prefabs from the project view, by design. This seems like a serious regression because now we can no longer multi select prefabs and change a value.

    1. Now you don’t need to select multiple prefabs and change their value: you can change the value of prefab variant (just once).

      But I think that you still have an option to do that in scene like you said.

    2. Yes this a limitation of the new system, and we understand this can be frustrating. Just like model prefabs, normal prefabs are now imported assets so they cannot be edited directly in the Project Browser. See the FAQ for more details: https://forum.unity.com/threads/faq.536647/

  8. Are there any changes to the serialization system with this update? Will it be possible to have polymorphic serialization?

    1. No these features are unrelated

  9. What about UI prefabs? does the prefab mode put them on a temp canvas?

    1. Whoah, that’s a really nice question. I hope it does.

    2. Yes we use a default Canvas for UI Prefabs. You can also specify your own UI Environment Scene for UI Prefabs by creating a Scene with your own Canvas and assign this in the Editor Settings (Look for ‘UI Environment’ under ’‘Prefab Editing Environments’)

  10. Hey, Unity, great job! Just to be clear, can prefab contain other prefab instances as children? Thanks

    1. Yes; Prefabs can contain other Prefab instances. I recommend to watch the video above to get a good overview of the new features (if you haven’t already).

  11. Really nice workflow :)