|
| 1 | +# Working with Prefabs |
| 2 | + |
| 3 | +In Unity, [Nested Prefabs](https://docs.unity3d.com/Documentation/Manual/NestedPrefabs.html) allow you to create Prefabs inside other Prefabs, and [Prefab Variants](https://docs.unity3d.com/Documentation/Manual/PrefabVariants.html) allow you to save a variation on an existing Prefab. |
| 4 | + |
| 5 | +When Unity imports a Model from a 3D modeling application such as Autodesk® Maya®, Unity creates a **Model Prefab**, which is a read-only representation of the FBX file's contents. You can't edit Model Prefabs in Unity, apart from [changing the import settings](https://docs.unity3d.com/2018.3/Documentation/Manual/class-FBXImporter.html). When the FBX file is modified inside the originating 3D modeling software, Unity updates the Model Prefab. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +If you want to add components, Materials, or change most other property values without affecting the original FBX file in Unity, convert the Model Prefab to an **FBX Linked Prefab**. This is a Prefab Variant of the exported FBX's Model Prefab. Prefab Variants allow you to override their base Prefabs' properties. |
| 10 | + |
| 11 | +> **NOTE:** While this method allows you to override properties, you cannot change the internal hierarchy of the Variant without breaking the link to the Model Prefab. This means you can add components to a Model Prefab in the Scene, such as a collider. However, you cannot apply any change back to the Asset without breaking the link. In this way, a Model Prefab is a *read-only* Prefab, because it is non-editable except for overrides in the Scene. |
| 12 | +
|
| 13 | +Using FBX Linked Prefabs is the best way to ensure that your Models continue to reflect any changes you make to your FBX files in external applications while still taking full advantage of the Prefab system. For example, while Linked Prefabs previously required the extra **FbxPrefab** component, FBX Linked Prefabs use only the Unity Prefab features. And you can create Variants of your FBX Linked Prefabs which all receive updates from the Model Prefab but provide a lot of flexibility. |
| 14 | + |
| 15 | +In addition, Variants give you some additional control over receiving updates from external applications. For example, if you have a Model with a Spot Light of size 10 and you override the size to 1 in your Variant, when the size and color change in the FBX file, the color changes but the size remains 1. |
| 16 | + |
| 17 | +> **IMPORTANT:** Because the Prefab Variant inherits data from the base Model Prefab, you cannot make structural changes to the Prefab Variant. This means that you cannot delete inherited child objects or re-arrange the order of inherited child objects on the Prefab Variant. |
| 18 | +
|
| 19 | +### Creating an FBX Linked Prefab |
| 20 | + |
| 21 | +You can either create an FBX Linked Prefab [from a GameObject](#fromGameObject) or generate it directly [from the selected .fbx or .prefab file](#fromFBXorAssetFile). If you are upgrading from a previous version of Unity, you can also [convert any existing](#conversion) Linked Prefabs you may have to the new FBX Linked Prefabs. |
| 22 | + |
| 23 | +When you convert a GameObject to an FBX Linked Prefab, the FBX Exporter exports each selected GameObject hierarchy and writes an FBX file and a Prefab Variant (`.prefab`) with the FBX as its base. |
| 24 | + |
| 25 | +When you generate an FBX Linked Prefab from a selected file, the FBX Exporter generates the FBX Linked Prefab without modifying the Scene: |
| 26 | + |
| 27 | +* If you select an FBX file, the FBX Exporter generates a Prefab Variant Asset file. |
| 28 | +* If you select a Prefab Asset file, the FBX Exporter generates a Prefab Variant Asset file and an FBX file. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +<a name="fromGameObject"></a> |
| 33 | +#### Converting a GameObject |
| 34 | + |
| 35 | +To replace the GameObject hierarchy with an instance of an FBX Linked Prefab: |
| 36 | + |
| 37 | +1. Right-click on the GameObject in the Hierarchy view and select __Convert To FBX Linked Prefab__ from the context menu. |
| 38 | + |
| 39 | +  |
| 40 | + |
| 41 | + Alternatively, you can use the main menu: __GameObject__ > __Convert To FBX Linked Prefab__ with the GameObject selected. |
| 42 | + |
| 43 | +2. Specify how you want to export the GameObject using the properties on the [Convert Options](#ConvertOptions) window and click **Convert**. |
| 44 | + |
| 45 | +FBX Linked Prefabs use the same rules as for exporting: all selected objects and their descendants are exported to a single FBX file. If you select both a parent and a descendant, the FBX Linked Prefab only exports the parent’s hierarchy. |
| 46 | + |
| 47 | +> **NOTE:** If the selected object is a Model Prefab instance, then the hierarchy is not re-exported: instead the FBX Linked Prefab links to the FBX file that already exists. |
| 48 | +
|
| 49 | +<a name="fromFBXorAssetFile"></a> |
| 50 | +#### Converting an FBX file or a Prefab |
| 51 | + |
| 52 | +To generate the FBX Linked Prefab from the selected file without modifying the Scene: |
| 53 | + |
| 54 | +1. Right-click on an FBX or Prefab Asset file in the Project view and select __Convert To FBX Linked Prefab__ from the context menu. |
| 55 | + |
| 56 | +  |
| 57 | + |
| 58 | + Alternatively, you can use the main menu: __Assets__ > __Convert To FBX Linked Prefab__. |
| 59 | + |
| 60 | +2. Specify how you want to export the GameObject using the properties on the [Convert Options](#ConvertOptions) window and click **Convert**. |
| 61 | + |
| 62 | +Depending on which type of file you selected, the FBX Exporter creates the FBX Linked Prefab in one of the following ways: |
| 63 | + |
| 64 | +* If an FBX file is selected, the FBX Exporter generates a Prefab Variant file with the selected FBX file as its base. |
| 65 | +* If a Prefab Asset file is selected, the FBX Exporter exports the Prefab to an FBX file and creates a new FBX Linked Prefab. |
| 66 | + |
| 67 | +<a name="ConvertOptions"></a> |
| 68 | +### Convert Options window |
| 69 | + |
| 70 | +When converting to an FBX Linked Prefab, the following window opens, displaying options for exporting: |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +#### Convert Option Properties |
| 76 | + |
| 77 | +| Property: | Function: | |
| 78 | +| :------------------------ | :----------------------------------------------------------- | |
| 79 | +| __Export Name__ | Specify the name of the FBX file to export. | |
| 80 | +| __Export Path__ | Specify the location where the FBX Exporter will save the FBX file. | |
| 81 | +| __Prefab Name__ | Specify the name of the FBX Linked Prefab's file. | |
| 82 | +| __Prefab Path__ | Specify the location where the FBX Exporter will save the FBX Linked Prefab file. | |
| 83 | +| __Source__ | Transfer the transform animation from this object to the __Destination__ transform.<br/><br/>**NOTES:**<br/> - __Source__ must be an ancestor of __Destination__.<br/> - __Source__ may be an ancestor of the selected object. | |
| 84 | +| __Destination__ | Which object to transfer the transform animation to.<br/><br/>This object receives the transform animation on objects between __Source__ and __Destination__ as well as the animation on the __Source__ itself. | |
| 85 | +| __Export Format__ | Select the format for the FBX Exporter to use when exporting the FBX file (ASCII or binary). | |
| 86 | +| __Include__ | __Convert to FBX Linked Prefab__ always exports both Models and Animation in the hierarchy. | |
| 87 | +| __LOD level__ | __Convert to FBX Linked Prefab__ always exports All levels of detail (LOD) available in the hierarchy for LOD groups. | |
| 88 | +| __Object(s) Position__ | __Convert to FBX Linked Prefab__ always resets the root object's transform during export. However, the Prefab maintains the global transform for the root object. | |
| 89 | +| __Animated Skinned Mesh__ | Check this option to export animation on objects with skinned meshes.<br/><br/>If unchecked, the FBX Exporter does not export animation on skinned meshes. | |
| 90 | +| __Compatible Naming__ | Check this option to control renaming the GameObject and Materials during export. <br/><br/>The FBX Exporter ensures compatible naming with Autodesk® Maya® and Autodesk® Maya LT™ to avoid unexpected name changes between Unity and Autodesk® Maya® and Autodesk® Maya LT™. During export the FBX Exporter replaces characters in Unity names as follows:<br/> - Replaces invalid characters with underscores ("\_"). Invalid characters are all non-alphanumeric characters, except for colon (":").<br/> - Adds an underscore ("\_") to names that begin with a number. - Replaces diacritics. For example, replaces "é" with “e”.<br/><br/>**NOTE:** If you have a Material with a space in its name, the space is replaced with an underscore ("_"). This results in a new Material being created when it is imported. For example, the Material named "Default Material" is exported as "Default_Material" and is created as a new Material when it is imported. If you want the exported Material to match an existing Material in the scene, you must manually rename the Material before exporting. | |
| 91 | +| __Don't ask me again__ | Check this option to use the same **Convert Option** properties and hide this window when converting to FBX Linked Prefabs in the future. You can reset this option by turning on the **Show Convert UI** option under **Edit** > **Project Settings** > **Fbx Export** in Unity's top menu. | |
| 92 | + |
| 93 | +> **NOTE:** For FBX Model filenames, the FBX Exporter ensures that names do not contain invalid characters for the file system. The set of invalid characters may differ between file systems. |
| 94 | +
|
| 95 | + |
| 96 | + |
| 97 | +<a name="conversion"></a> |
| 98 | +### Converting from Linked Prefabs to FBX Linked Prefabs |
| 99 | + |
| 100 | +To convert existing Linked Prefabs to FBX Linked Prefabs, follow these steps: |
| 101 | + |
| 102 | +1. Fix any name discrepancies that were previously handled by the [name remapping functionality for Linked Prefabs](prefabs.md#Remapping) before converting. FBX Linked Prefabs do not handle name remapping. If you start to add game logic to components, and then the objects in the FBX get renamed, you are at risk of losing the components. This can happen because the old GameObjects are deleted and new objects with the new names are added in their place. |
| 103 | + |
| 104 | +2. Right-click the Linked Prefab file and select **Convert to FBX Linked Prefab** from the context menu. |
| 105 | + |
| 106 | +  |
| 107 | + |
| 108 | +> **NOTE:** This re-exports the Linked Prefab to a new FBX file, and it is no longer connected to the original FBX. |
0 commit comments