Prefab Mode in Context now in 2020.1 beta

Unity 2020.1 has a new improvement to the Prefab workflows called Prefab Mode in Context.

With Prefab Mode, you could always edit a Prefab in isolation. Now you can also open a Prefab in context. When you open Prefab Mode this way, you can see the context of the Prefab instance in the Scene view (but locked for editing) even though you are not editing the instance but rather the Prefab Asset itself (like always, in Prefab Mode).

You can try it out today in the Unity 2020.1 beta. Check out the documentation too.

Editing in Context
When you open Prefab Mode via a Prefab instance in the Hierarchy window, this opens Prefab Mode in Context. When you open Prefab Mode this way, you can see the context of the Prefab instance in the Scene view even though you are not editing the instance but rather the Prefab Asset itself. So if you for example open Prefab Mode in Context via a Prefab instance in a scene, then you can see the surroundings in that scene while editing the Prefab and the Prefab is shown with the same lighting conditions as in the scene.


A Prefab opened in Prefab Mode in Context, with the surrounding context displayed in gray scale.
(Pictured assets from the Asset Store package POLYGON - City pack)

If you have a Prefab instance that you do not want to open in context, but rather want to open in isolation, you can hold down the Alt key while clicking the Open button or the arrow button to open Prefab Mode. It’s also possible to setup a custom shortcut in the Shortcuts window for the command “Stage > Edit Prefab in Isolation”.

Controlling how the context is displayed
The visual representation of the context is by default shown in gray scale to visually distinguish it from the Prefab contents being edited. However, a control in the Prefab bar can be used to set it to any of the following states:

  • Normal - the context is shown with its normal colors
  • Gray - the context is shown in gray scale
  • Hidden - the context is hidden entirely so only the Prefab content is visible


The Prefab Mode controls in the Prefab bar in at the top of the Scene view, including the Context control and the Show Overrides toggle

The objects that are part of the context are not selectable, nor will they show in the Hierarchy. This is to allow you to focus on editing your Prefab without accidentally selecting other unrelated objects, and without having a cluttered Hierarchy window. However, when you move objects around that are part of the Prefab contents, you can use the snapping features in Unity to snap to objects in the context, provided the context is not set to Hidden.

Previewing overrides from the Prefab instance
In Prefab Mode in Context, the Prefab contents are shown at a position that matches that of the Prefab instance it was opened through. This means the root Transform of the Prefab contents may be previewed with different position and rotation values than the Prefab Asset actually has. These values cannot be edited in Prefab Mode in Context. If you need to edit them, you can either open the Prefab in isolation, or you can select the Prefab Asset in the Project window and edit the values in the Inspector.

Apart from the root Transform properties, a Prefab instance can have other properties overridden as well, which may drastically change its appearance compared to the Prefab Asset it’s an instance of. You can preview these overridden values from the Prefab instance while in Prefab Mode in Context by enabling the “Show Overrides” toggle in the Prefab bar. While enabled, any properties that are overridden on the Prefab instance are previewed the same way on the Prefab contexts and cannot be edited. To be able to edit those properties, disable the “Show Overrides” toggle again.

Let us know how this is working for you!
Is the Prefab Mode in Context feature useful in your workflows? What do you use it for?

We think the feature may be useful particularly for level design tasks and for UI (uGUI) work but let us know what your own experience is.

Are you encountering any issues? Bugs or things that are confusing or unclear? Let us know!

The user manual page for the feature are not yet ready, but the above covers most of what it’s going to say about the feature. If anything needs to be explained better, let us know as well!

13 Likes

Is there a way to control gray out for emitted draw calls? (Graphics.Draw… methods and renderers created at runtime in custom batching systems). I may emit some draw calls based on prefab content, but Unity isnt aware and would simply gray out everything.

At minimum we should have an api to change prefab stage GrayOut mode from code, if we know the in built check is not good enough for some cases

Prefab Mode is not part of Play Mode. Even when the editor is in Play Mode, objects in Prefab Mode don’t go into Play Mode. As such, runtime graphics APIs are not relevant for Prefab Mode as far as I understand.

Even if you use runtime graphics APIs in Edit Mode (so they’re visible also when not in Play Mode), we can’t give runtime APIs knowledge of Editor specific concepts like Prefab Mode, since those concepts don’t exist in the runtime engine.

That said, we’re interested in seeing if we can address your use case. If you file a bug report with your project and how it’s using these APIs in Prefab Mode, we can have a look at whether there’s something we can do. Thanks!

If this is useful? :slight_smile: This is how it should’ve been done from the beginning. :slight_smile: Love this feature.

1 Like

Are there plans to make Prefab Stages more open ended via API’s? For example, being able to open a stage and create a gameobject inside of it as opposed to just a prefab?

Prefab Stages are for Prefabs, but in 2020.1 you can create your own type of stage as well by inheriting from PreviewSceneStage (which PrefabStage also inherits from):
https://docs.unity3d.com/2020.1/Documentation/ScriptReference/SceneManagement.PreviewSceneStage.html
https://docs.unity3d.com/2020.1/Documentation/ScriptReference/SceneManagement.StageUtility.GoToStage.html

However, this is not really related to the Prefab Mode in Context feature.

1 Like

That’s what I thought, but I couldn’t find the docs on it. The reason I brought it up here was to ask if this in context mode will also be supported in the generic stage api

The ability to see the context is implemented in PrefabStage and isn’t built into PreviewSceneStage. There are Prefab specific aspects to it, like hiding the instance in the scene so it doesn’t overlap with the opened Asset which is positioned in the same place. We’d be happy to hear about use cases for showing context in custom stages so we can have it help inform our prioritization.

Good job. Prefab workflow really needed this feature, especially for UI related prefabs.

1 Like

I tried this, but it doesn’t show the prefab at the right location.
It shows the prefab at the Position in the prefab, not the Position where it is on the map.
This makes the context part not work at all.
Testing this in 2020.1.0b12

Prefabs in place is very welcome, thanks for that!

Will you also add anway to customise prefab previews?

The thumbnail gallery in the project browser shows prefabs too dark, and there is currently no way to change the background color and the light intesity of the generated thumbnails.

1 Like

We haven’t seen this issue before. Do you have any non-uniformly scaled Transforms as parents of the Prefab instance in question? If it still happens in the latest beta, can you file a bug report and post the case number here so we can investigate?

Guys please, the new Prefab workflow was already cumbersome to work with when you want to move or replace / take out things from a prefab (requiring to unpack) but now this is hidden in a second drop down menu on top - this is just painful

How about you enter a third button to the popup that appears when you try to move something in a prefab
that says “Unpack Prefab” / “Unpack Completely” - This would make this much less painful and save the user experience. There is nothing worse than multiple layers deep drop down menus for common actions.

6057389--655652--upload_2020-7-5_18-13-39.png

Especially 3D Artists import a lot of meshes which are then always prefabs which need to be unpacked each time

It was user error on my side.
I though Alt+click was context mode and Click was isolation.

The issue was that some custom rendering stuff was (like our terrain system) is still visible in isolation.
I need to find a way to support this workflow (although not being default, most people in our team won’t use it)

â—ŹPrefab AllApply
â—ŹUnpack Prefab Shotcut
These two are absolutely necessary Please

googleTranslate

1 Like

Is there a way to open a prefab instance in your scene with in-context prefab mode using script? I know I can open the asset, but I’d really like to be able to open it in-context.

AssetDatabase.OpenAsset() has an optional int line parameter, if you pass the instanceID of the Prefab instance object then we will open Prefab Mode In Context of that instance.

Example: If you have a Prefab instance in the scene you can use:

AssetDatabase.OpenAsset(prefabAsset, yourInstanceGameObject.GetInstanceID());```

We know that this approach seems non-obvious and intend to improve this with a more explicit API in the future.
2 Likes

Maybe ask the docs team to put it in the scripting documentation in the meantime? It probably takes a good amount of time until a more explicit API lands.

Good idea.

1 Like

PrefabUtility.GetOriginalSourceOrVariantRoot doesn’t seem to exist, but I managed to make if work with other functions in PrefabUtility

Thanks for the help

var prefabAsset = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(myPrefabInstanceInScene);
AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath(prefabAsset, typeof(GameObject)), myPrefabInstanceInScene.GetInstanceID());