Version: 2018.4
Prefabs
Editing a Prefab in Prefab Mode

Creating Prefabs

In Unity’s 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
system, Prefab Assets act as templates. You create Prefab Assets in the Editor, and they are saved as an AssetAny media or data that can be used in your game or Project. An asset may come from a file created outside of Unity, such as a 3D model, an audio file or an image. You can also create some asset types in Unity, such as an Animator Controller, an Audio Mixer or a Render Texture. More info
See in Glossary
in the Project window. From Prefab Assets, you can create any number of Prefab instances. Prefab instances can either be created in the editor and saved as part of your ScenesA 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
, or instantiated at runtime.

Creating Prefab Assets

To create a Prefab Asset, drag a GameObjectThe 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
from the Hierarchy window into the Project window. The GameObject, and all its components and child GameObjects, becomes a new Asset in your Project window. Prefabs Assets in the Project window are shown with a thumbnail view of the GameObject, or the blue cube Prefab icon, depending on how you have set up your Project window.

Two prefabs (LeafyTree and “Vegetation”) shown in the Project window in two-column view (left) and one-column view (right)
Two prefabs (“LeafyTree” and “Vegetation”) shown in the Project window in two-column view (left) and one-column view (right)

This process of creating the Prefab Asset also turns the original GameObject into a Prefab instance. It is now an instance of the newly created Prefab Asset. Prefab instances are shown in the Hierarchy in blue text, and the root GameObject of the Prefab is shown with the blue cube Prefab icon, instead of the red, green and blue GameObject icon.

A Prefab instance (LeafyTree) in the scene
A Prefab instance (LeafyTree) in the scene

Creating Prefab instances

You can create instances of the Prefab Asset in the Editor by dragging the Prefab Asset from the Project viewA view that shows the contents of your Assets folder (Project tab) More info
See in Glossary
to the Hierarchy or 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
.

Dragging a Prefab RedPlant into the Scene
Dragging a Prefab “RedPlant” into the Scene

You can also create instances of Prefabs at runtime using scripting. For more information, see Instantiating Prefabs.


  • 2018–07–31 Page published

  • Nested Prefabs and Prefab Variants added in 2018.3

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