Version: Unity 6 Beta (6000.0)
Language : English
Creating Prefabs
Instance overrides

Editing a Prefab in Prefab Mode

To edit a PrefabAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary
Asset, open it in Prefab Mode. Prefab Mode allows you to view and edit the contents of the Prefab Asset separately from any other GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
in your SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
. Changes that you make in Prefab Mode affect all instances of that Prefab.

Entering and exiting Prefab Mode

You can edit a Prefab Asset in isolation, or in context.

Left: editing a Prefab in isolation. Right: editing a Prefab in context.
Left: editing a Prefab in isolation. Right: editing a Prefab in context.
  • In isolation: When you edit a Prefab in isolation, Unity hides the rest of your current working Scene, and you only see the GameObjects that relate to the Prefab itself (plus, optionally, a pre-set editing environment - see below).

  • In context: When you edit a Prefab in context, the rest of your current working Scene remains visible, but locked for editing.

Editing in isolation

You can begin to edit a Prefab in Prefab Mode in several ways. To open a Prefab Asset and edit it in isolation you can do it in the following ways:

  • Double-click the Prefab Asset in the Project window
  • Select a Prefab Asset in the Project windowA window that shows the contents of your Assets folder (Project tab) More info
    See in Glossary
    and click the Open Prefab button in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
    See in Glossary
    window
A Prefab Asset selected in the Project window (left), and the Open Prefab button visible in the inspector (right)
A Prefab Asset selected in the Project window (left), and the Open Prefab button visible in the inspector (right)

When you enter Prefab Mode in isolation, Unity only shows the contents of that Prefab in the Scene viewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
See in Glossary
and the Hierarchy window. In the following image, the root of the Prefab is a regular GameObject - it doesn’t have the blue Prefab instance icon.

The Scene view and Hierarchy, with Prefab Mode in isolation
The Scene view and Hierarchy, with Prefab Mode in isolation

In Prefab Mode, the Scene view displays a breadcrumb bar at the top. The rightmost entry is the currently open Prefab. Use the breadcrumb bar to navigate back to the main Scenes or other Prefab Assets that you might have opened.

The breadcrumb bar at the top of the Scene view, visible when in Prefab Mode
The breadcrumb bar at the top of the Scene view, visible when in Prefab Mode

The Hierarchy window displays a Prefab header bar at the top which shows the currently open Prefab. You can use the back arrow in the header bar to navigate back one step, which is equivalent to clicking the previous breadcrumb in the breadcrumb bar in the Scene view.

The back arrow in the header bar of the Hierarchy window, visible when in Prefab Mode
The back arrow in the header bar of the Hierarchy window, visible when in Prefab Mode

Editing in context

Alternatively, you can open a Prefab Asset in Context via an instance of that Prefab. Ways of doing that include:

  • Select a Prefab instance in the Hierarchy window and click the Open button in the Inspector window
  • Select a Prefab instance in the Hierarchy window and press P on the keyboard. This is the default keyboard binding
  • Use the arrow button next to the Prefab instance in the Hierarchy window
The Open button in the Inspector when a Prefab Instance is selected
The Open button in the Inspector when a Prefab Instance is selected
The arrow button next to a Prefab in the Hierarchy window
The arrow button next to a Prefab in the Hierarchy window

By default, Unity displays the visual representation of the context in gray scale to visually distinguish it from the Prefab contents you edit. However, you can use the Context: control in the Prefab bar to set it to any of the following states:

  • Normal - Shows the context with its normal colors
  • Gray - Shows the context in gray scale
  • Hidden - Hides the context 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 Prefab Mode controls in the Prefab bar in at the top of the Scene view, including the Context control and the Show Overrides toggle

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

In Prefab Mode in Context, Unity displays the Prefab contents at a position that matches that of the Prefab instance it was opened through. This means that you might preview the root TransformThe Transform at the top of a hierarchy of Transforms. In a Prefab, the Root Transform is the topmost Transform in the Prefab. In an animated humanoid character, the Root Transform is a projection on the Y plane of the Body Transform and is computed at run time. At every frame, a change in the Root Transform is computed, and then this is applied to the GameObject to make it move. More info
See in Glossary
of the Prefab contents with different position and rotation values than the Prefab Asset actually has.

You cannot edit these values in Prefab Mode in Context. If you need to edit them, you can either open the Prefab in isolation, or select the Prefab Asset in the Project window and edit the values in the Inspector.

Apart from the root Transform properties, you can also override other properties of a Prefab instance, which might drastically change its appearance compared to the Prefab Asset it’s an instance of. To preview these overridden values from the Prefab instance, while in Prefab Mode in Context enable the Show Overrides toggle in the Prefab bar. While this setting is enabled, any properties that you override on the Prefab instance are previewed the same way on the Prefab contexts and you cannot edit them. To edit those properties, disable the Show Overrides toggle again.

Auto Save

Prefab Mode has an Auto Save setting in the top right corner of the Scene view. When it is enabled, Unity automatically saves any changes that you make to a Prefab to the Prefab Asset. Auto Save is on by default.

The Auto Save toggle in the upper right corner of the Scene view in Prefab Mode
The Auto Save toggle in the upper right corner of the Scene view in Prefab Mode

If you want to make changes without automatically saving those changes to the Preset Asset, disable the Auto Save checkbox. In this case, Unity asks you if you want to save unsaved changes or not when you exit Prefab Mode for the current Prefab. If editing a Prefab in Prefab Mode seems slow, turning off Auto Save might help.

Changing between isolation or in context mode

When you open Prefab Mode via a Prefab Asset, Unity displays the contents of the Prefab in isolation. However, 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. For example, if you open Prefab Mode in Context via a Prefab instance in a Scene, then you can see the surroundings in that Scene while you edit the Prefab. The Prefab is also 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
A Prefab opened in Prefab Mode in Context, with the surrounding context displayed in gray scale

If you have a Prefab instance that you do not want to open in context, but want to open in isolation, hold down the Alt key and click the Open button or the arrow button to open Prefab Mode. You can also set up a custom shortcut in the Shortcuts window for the command Stage > Edit Prefab in Isolation.

Undo

When you make changes to a Prefab Asset while in Prefab Mode, you can only undo those changes while still in Prefab Mode. Once you exit Prefab Mode for a given Prefab Asset, your edits relating to that Prefab Asset are no longer available in the undo history.

Editing Environment

You can assign a Scene as an editing environment to be used with Prefab Mode in Isolation. This allows you to edit your Prefab against a backdrop of your choosing rather than an empty Scene. This can be useful to see how your Prefab looks against a specific scenery of your choice. Unity only uses this editing environment when you open Prefab Mode in Isolation.

You cannot select the GameObjects in the Scene that you assign as the editing environment when in Prefab Mode, nor do they show in the Hierarchy. This is so you can focus on editing your Prefab without accidentally selecting other unrelated GameObjects, and without having a cluttered Hierarchy window.

To set a Scene as the editing environment, open the Editor window (top menu: Edit > Project Settings, then select the Editor category) and go to the Prefab Editing Environment section. Use the Regular Environment setting for “non-UI” Prefabs, and the UI Environment setting for UI Prefabs. UI Prefabs are those which have a Rect Transform component on the root, rather than a regular Transform component. “non-UI” Prefabs are those which have a regular Transform component.

Prefab editing environment settings in the Editor Project Settings
Prefab editing environment settings in the Editor Project Settings
Creating Prefabs
Instance overrides
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961