# Create Prefab (Pro)

### Introduction

While Unity provides a standard prefab workflow, **realvirtual goes a step further** with its own **Create Prefab** function. This tool is designed specifically for **industrial simulation workflows**, allowing you to generate **self-contained, reusable assets** that include not only meshes and hierarchy but also the logic components that define behavior—such as drives, signals, sensors, and automation interfaces.

> 💡 **Hint:** You should typically use this function **after preparing and optimizing your GameObject**—for example, after using Combine Meshes—to turn it into a **lightweight, modular component**.

### Overview

The `Create Prefab` function in realvirtual creates a prefab asset that includes:

* The complete **GameObject hierarchy**
* All associated **meshes** (combined or separate)
* All attached **realvirtual components**, such as:
  * Drives
  * Signals
  * Sensors
  * Kinematic groups
  * Custom logic or automation interfaces

This ensures the prefab is fully portable and ready for use in any simulation context built with realvirtual.

### Scene Mesh Handling

Unlike Unity’s standard workflow, realvirtual's `Create Prefab` works seamlessly even when:

* Meshes are still **embedded in the scene**, for example after a **CADLink import**
* Meshes have been **combined** using the Combine Meshes utility

It acts similarly to an **FBX export**, but instead of creating an external file, it generates a single prefab **containing all geometry, hierarchy, and logic in one asset**—ready for reuse and versioning in your simulation workflows.

### When to Use

* After optimizing an imported CAD structure
* When creating **reusable standard components**
* When preparing modular assets for **parts libraries or versioned assets**
* Before exporting or distributing simulation-ready components

### How to Use

1. **Select the root GameObject**\
   Choose the GameObject that includes all child objects and components you want to include in the prefab.
2. **Run Create Prefab**\
   Right-click on the selection in the Hierarchy and choose:\
   \&#xNAN;**`realvirtual/Create Prefab`**

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-b452c0dd08829451844b81043cb851fdc78679ac%2Fmesh-createprefab.png?alt=media" alt=""><figcaption><p>Create prefab in Gameobject context menu</p></figcaption></figure>

3. **Result**\
   The prefab will be automatically created under the **`Assets/`** folder of your project.

<figure><img src="https://260262196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpYxFg97YnJX96UzNNTSd%2Fuploads%2Fgit-blob-370ccd54b6921391c7db1ca17993ea15f32c8af3%2Fmesh-exportedprefab.png?alt=media" alt=""><figcaption><p>Exported prefab</p></figcaption></figure>

3. **Organize**\
   If needed, manually **move the prefab** to your desired location within the Unity project (e.g., `Assets/Prefabs/[ExportedPrefab]`).

> 📦 The resulting `.prefab` file contains the full structure, geometry, and behavior. It’s fully reusable across scenes and projects and supports realvirtual's simulation features out of the box.
