# Prefabs in Scene2Ds

In order to use **Prefabs**, one must understand the different ways to manipulate them. This is detailed in the following sections:

* [Creating Prefabs](#creating-prefabs)
  * [Objects Within a Frame](#objects-within-a-frame)
  * [Objects Outside of a Frame](#objects-outside-of-a-frame)
* [Editing the Prefab Asset](#editing-the-prefab-asset)
* [Editing a Prefab Instance](#editing-a-prefab-instance)
* [Unpacking a Prefab](#unpacking-a-prefab)

## Creating Prefabs

To create a **Prefab**, go to the **Scene Outliner** and select the **Objects** that will compose the **Prefab**, then right-click and click on `Make Prefab`. This will create a **Prefab** consisting of the selected **Objects** and a new **Prefab** **Asset** will be generated in the **Asset Manager**.

![Creating a Prefab.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-c9a9fab0745af5f84f058aa898ee7fd0b9a4c75e%2F2dprefabsexample1.gif?alt=media)

New instances of the **Prefab** can be created by either duplicating the existing **Prefab** in the **Scene Outliner** or by dragging the **Prefab Asset** from the **Asset Manager** to the **Scene Outliner** or the **Scene**.

![Creating new instances of a Prefab.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-84b17fa9371f92f4b66b07e890d809fb15902322%2F2dprefabsexample2.gif?alt=media)

For creating **Prefabs** in **Scene2Ds**, there are two cases to consider: if **Objects** are already a part of a **Frame** or if they are standalone.

### Objects Within a Frame

Making a **Prefab** in a **Scene2D** from an already existing **Frame** will create a new **Prefab** and put the **Frame** *child* **Objects** into a **Prefab** (essentially a **Frame**), and not the original **Frame** itself. All the properties of the initial **Frame** will be copied into the newly created **Prefab**.

See an example below. Here, a **Prefab** is created from a **Frame** with a vertical `Layout` that contains two **Sliders**.

![Before Making into Prefab.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-4c18a5c72697513bbd37b41df00ea0911bcd242b%2Fprefab2dexamplebefore.png?alt=media)

![After Making into Prefab.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-bbaac1fda2c5bb77205b41f9f812d752848fb8e7%2Fprefab2dexampleafter.png?alt=media)

Note that the **Prefab** consists of the two **Sliders** that were *children* of the **Frame**, as well as the **Frame's** `Layout` property that was set to vertical.

### Objects Outside of a Frame

Creating a **Prefab** from multiple **Objects** that are not already part of a **Frame** will result in a **Prefab** (essentially a **Frame**). It will contain default properties and all the **Objects** that were packed into the **Prefab**.

See an example below:

![Before Making into Prefab.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-b85772dcdb6c0849102acc5454eb5c32f3734ef6%2F2dprefab3real.png?alt=media)

![After Making into Prefab.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-a9fd15d25edee17b8bed9b2a297ab90435806626%2F2dprefab4.png?alt=media)

## Editing the Prefab Asset

To edit the **Prefab** **Asset**, double-click the **Prefab** in the **Asset Manager**. This will open the **Prefab View** in both the **Scene Outliner** and **Attribute Editor**. It is also possible to right-click on the **Prefab** in the **Scene Outliner** and click the `Edit Prefab` button.

![Editing Prefab from Scene Outliner.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-868c10693473345252a462aa1698b682d2fb765a%2Fprefabs3.png?alt=media)

![Editing the Prefab Asset.](https://github.com/cgi-studio-gmbh/incari-doc/blob/2023.2/objects-and-types/.gitbook/assets/creatingprefabimage3.gif)

The **Prefab** **View** is indicated by a purple circle. Changes made here affect all instances of the **Prefab**.

For the changes made in the **Prefab Asset** to take effect, it is necessary to save them by pressing the `Save prefab` button on the top right corner of the **Viewport**.

![Prefab view.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-69498db20fa0cd22394664fa5409ac501454aa63%2Fprefab-view2.png?alt=media)

## Editing a Prefab Instance

Each **Instance** of a **Prefab** can be modified on its own and this overrides the **Attributes** from the **Prefab Asset**. To do this, simply edit the **Object** in the **Prefab** instance.

![Prefab instance override.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-6f66ca2d40e36f02b6a6e213dc10b12bb5826b06%2F2dprefabsexample4.gif?alt=media)

## Unpacking a Prefab

Unpacking a **Prefab** in a **Scene2D** will result in a new **Frame** that has all the properties that were set for the **Prefab**. The new **Frame** is essentially a copy of the **Prefab**.

![Before Unpacking.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-420a71cfbd94931cd24295b902e2fd26a0d18fec%2F2dprefab5.png?alt=media)

![After Unpacking.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-e2b4171d028b2884806ccd3bc707b531c17e415a%2F2dprefab6.png?alt=media)

In the case of a **Prefab** that contains only one **Frame** as a *child*, the **Frame** will be moved to the position of the **Prefab** parent.

![Before Unpacking.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-e6e9c090a6ef6be14dfce71cd322882dd1d6a910%2F2dprefab7.png?alt=media)

![After Unpacking.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-20b980b1338a7a96ffa78adc329056f7645ef7b9%2F2dprefab8.png?alt=media)

When unpacked, the **Objects** of a **Prefab** will be moved to the same level in the **Scene Hierarchy** that the **Prefab** was on. This means that the *parent* of the **Prefab** is now the *parent* of the **Objects** and not the **Prefab**. The **Prefab Instance** is also deleted.

Any edits given to **Objects** of a **Prefab** via overrides remain once unpacked.
