# Logic in Prefabs

**Prefabs** contain their own **Logic** and it applies to all instances of the **Prefab**. The **Prefab** **Logic** can be incorporated into the **Scene Logic** via a **Prefab Node**, which can be found in the **Logic Editor** by choosing the **Prefab** tab on the left Menu.

![Prefab Node.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-9a8160e46a09c9945942d1fb4054821bd5350c74%2Flogicinprefabimage120232.png?alt=media)

To open the **Prefab Logic** graph in the **Logic Editor** either double-click the **Prefab Node** in the **Logic Editor** or the **Prefab Asset** in the **Asset Manager**. The user can then get started with:

* [**Nodes**](#nodes)
* [**Variables**](#variables)

## Nodes

The **Prefab Logic** has four **Nodes** by default: **Prefab Input**, **Prefab Output**, **On Creation**, and **On Destruction**. These represent the **Input** and **Output** of the **Prefabs** as well as two events on the creation and destruction of the **Prefab Node**, respectively.

![Prefab Logic.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-eb759876ade8cb93b35194fcc4579a69ecc32050%2Fimage-20231218-151201.png?alt=media)

The **Input** and **Output** **Nodes** can have their **Attributes** customized: **Input Sockets** can be added to the **Prefab Input** **Node** and **Output Sockets** to the **Prefab Output** **Node**. These changes will then be reflected in the **Prefab Node**.

The **On Creation Event Node** is triggered once the **Prefab** is created in the **Scene**, which happens when the **On Scene Show Event Node** is fired or when an **Object** is created dynamically via **Logic**.

The **On Destruction Event Node** is triggered once the **Prefab** is destroyed in the **Scene**, which happens after the **Scene** is unloaded with [**Unload Scene**](https://docs.incari.com/incari-studio/2023.2/toolbox/incari/screen/unloadscene) or when the **Object** is destroyed via **Logic** with the **Destroy** **Object** **Node**.

## Variables

It is possible to expose every **Prefab** **Variable's** default value to be set per instance from the **Attribute Editor** of the **Prefab Instance**. Currently only these **Variable** types are supported for this feature: **AssetID**, **Binary**, **Boolean**, **Byte**, **Color**, **Float**, **Integer**, **MaterialID**, **MediaID**, **String**, **TextureID** and *Vectors*.

The user must first access the **Prefab** tab of the **Logic** **Editor**, click on the **Variables** tab, and then click on `Expose Icon` of an already existing variable. If the `Expose Icon` is enabled for a **Variable**, then every instance of the **Prefab** has an `Entry` in its **Attribute Editor** under `Prefab → Variables` that shows the default value of the **Variable** that is settable as well.

![Accessing Variables in Prefabs.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-a56388d4a0c474894e5654533ba3ea0b8799c3b9%2Fprefabvariablegifexample.gif?alt=media)

The image below showcases all **Variable** types created in the **Prefabs’s Logic Editor**. However only the **Variables** having the `Expose/Hide Icon` are the ones that can be visible in the **Attribute Editor** of the **Prefab's** **Instances**. For example, the **Variable** named `Byte` of type **Byte** will not be visible because its `Expose Icon` has been disabled.

![Variables in the Logic Editor of the Prefab](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-5c5d75325643b2918b92cf08533f260f592522d6%2Fvariablesexample1.png?alt=media)

The next image shows how these **Variables** will be shown in the **Attribute Editor** of each instance of the **Prefab** where the user can set their default values. This is accessed by simple clicking on the **Prefab Instance** in the **Scene Outliner** and locating the **Attribute Editor**.

![Variables in the Attribute Editor of a Prefab Instance.](https://2561100106-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ff6JZovzOqBctA4C1o76u%2Fuploads%2Fgit-blob-7574e073a9511ab778f40385515f7648d85d31ab%2Fvariablesexample2.png?alt=media)
