How Unity Prefabs Work
To understand what kind of changes will break a link between a Unity prefab and the FBX file it was created from.
1 FBX file exported from Maya or other 3d packages
Enlightenment, but also a better grasp of when prefabs will need to be reconstructed and what kind of changes automatically come across as FBX files are updated.
Metadata – A term used for the “Meta” file associated with each asset when the project is set to “Use Source Control”. (Details on Project Settings Coming Soon)
GameObject – Any Unity object placed inside a scene, could also be called a transform or simply “object” from the content creator’s viewpoint.
Prefab – A Unity object that acts as an interface for the user to directly customize, script or otherwise tweak for Unity to store. This is a Unity copy of the transforms of a particular FBX or GameObject. When saved in a readable format, it is written in YAML, a human readable markup language.
Scene – A standalone file that holds references to other objects as well as holds unique objects within it.
Scene Hierarchy – Referring to the currently opened “Scene” within Unity. Any object that is loading inside the scene is essentially “part of” that Scene’s hierarchy. When the “Scene” is saved, the objects are then written inside the “Scene” file.
Project Hierarchy – This is the same as a windows explorer or finder window. It is a view of the file structure of the Unity project. It will NOT show any meta files as they are seen as the content metadata. It also only shows the files that Unity knows how to process, unknown formats will simply have a broken looking icon.
How to Make A Prefab
This is done simply by dragging a transform, or GameObject from the “Scene Hierarchy” to a location in the “Project Hierarchy”. The Object will then turn blue, notifying you of a new linkage between the two files.
What Does a Prefab Do?
It does a lot, but without getting into the full breadth of its use cases, its most broad definition: it creates a file that can be referenced in multiple places but can still be easily edited from the “source” and have those changes go across multiple references. Much like the Animation References we set up earlier.
Important Unity Colors
Different colors are used to indicate the “Status” of a prefab or GameObject inside your scene view.
Black– These files are unique to this scene. In their current state, they cannot be used or referenced in any other scene.
Blue– Indicates that there is a “Prefab Link” for this file or a “project version” that it is getting its content and information from.
Red– Shows that the original reference to this file is deleted or missing and is potentially broken.
Scene Changes VS Project Changes
Changes can be made to either the “Project” version of a prefab or the “Scene” version.
Once a prefab is placed inside a scene, it has the ability to have Scene specific changes. These are changes that are stored within the scene itself and will NOT be pushed to other references of this prefab in other scenes. This is typically what you want for Transform values as these are unique to the placement of that particular object. Component changes are sometimes necessary to keep in the scene as well, but often those changes should be propagated to other instances of that prefab. This can be done by hitting Apply in the inspector. This will then force the update of the “Project” version and all the other instances of those objects, provided the other objects do not have scene-specific changes on the component already.
Scene specific changes are highlighted in the inspector with Bold text on the components that have been changed locally.
Scene specific changes are considered a higher priority than prefab changes. So will override any changes made at the prefab level.
Prefab objects inside the project can also be directly edited. Changes made here will get pushed to ALL the instances of that object, provided that there are not scene-specific changes on those components already. The limitation of working inside the Project View is that it will only display one level deep of the hierarchy. Components on the root or child of the root can be edited, but nothing below that. If edits deeper in the hierarchy are desired, it’s best to drag that object into the scene, make the changes then hit the “Apply” button in the inspector.
Make sure prefabs are stored (saved) with no transforms on them. This means, effectively, zeros across translate and rotation and One on the scales.
What Links A Prefab and an FBX
At its core, when a Prefab is made from an FBX file it is essentially a reduced copy of the FBX. It duplicates the hierarchy and creates unity components on the transforms which link with the FBX, however, this is just a shell or skeleton of the FBX.
The types of components that link directly to the FBX file are: Meshes (both Skinned and Static), Avatars and Animations. If the source FBX file is deleted, the hierarchy of the prefab will remain, but the links to the meshes will be destroyed and will no longer display.
The components that will be disconnected from a prefab when the FBX is deleted can be found in the project window, underneath the root object of the FBX:
The components are listed in the project view of the FBX.
The image below lists them in this order:
- Mesh Component
- Animation Component
- Avatar Component
Changes that WON’T Update in the Prefab
One of the biggest pain points of prefabs is that there are certain changes that will not come across to the prefab automatically. It requires often a full rebuild of those prefabs, which can get annoying, to say the least, especially when you have large numbers of custom components to hook up. The best advice I have is to automate the creation of these prefabs by creating custom editor scripts that will take that FBX file and output the prefab for you either automatically, or through an editor setup process.
FBX edits that will update in an FBX:
Static Mesh Changes – Meshes WITHOUT skinning information
UV Changes – Updating or changing the UV layout of a mesh
Animation Changes – Updating keyframes in an animation
FBX edits that will not update inside the Prefab:
Skinning Changes – If you update or change the skinning on a model
Hierarchy Changes – This includes renaming or reordering the hierarchy
Of course, if you want Unity’s definition of a prefab, you can check on their site here: https://docs.unity3d.com/Manual/Prefabs.html
Be sure to share this if you found value in it! If you have comments or suggestions, please email me directly or leave feedback in the comments.
Contact me anytime! I am happy to help.
15 Free Unity Asset Tips
Join the community and stay up to date with the whats happening with the site!
I'll also throw in my top 15 tips for managing assets inside Unity!