Programming Documentation

logo

Programming Documentation

Search
Light Mode
Contact Us

Contact us

No results for your search.
Sorry, an unexpected error occurred

A prefabricated object or prefab for short is a gameObject that has been created into a template that can be reused multiple times in scenes.


Prefabs are stored in the project's folders, and you can drag a prefab into a scene (or into the hierarchy window) to create an instance of the prefab.


Editing a prefab in the scene doesn't change the prefab file, only that instance of the prefab. Each prefab instance has a list of overridden values, which are different from the prefab's defaults. You can also add additional child gameObjects or additional components, which are just another form of overrides.


In the example below, the radius of the sphere collider is changed from its default value of 0.5 to 1. That adds an override to the "Overrides" dropdown.


Prefabs are also necessary for big projects like ours with multiple people in different locations. Using source control (GitHub, Perforce, etc) and not using prefabs would result in many hands in the scene at the same time and cause endless conflicts. Editing the scene on the prefab level doesn't change the scene so there can be more work done simultaneously with more safety.


Prefabs are useful for encapsulation. Anything can reference anything in a scene, like having all variables in code be public. In large projects, that can make it very time consuming to change things without breaking other things. A prefab acts as a smaller chunk, ideally self-contained. Also, if a prefab instance has an inspector reference to something else, it's easy to see in the "Overrides" dropdown. That way, you don't need to check everything in a prefab instance to figure out whether it depends on something you're changing.


For more information checkout Unity's Prefab Documentation: HERE


Prefabs and the develop scene

The develop scene is the main scene we use in the prototype and production project and each are compromised of multiple prefabs. They are indicated by a blue colored cube in the hierarchy.



⚠️
When making changes to a prefab you need to find the object in the project files or open it from the inspector to make changes.
⚠️
If the prefab contains prefabs inside it continue to open them from the inspector.
🚫
DO NOT make changes on prefabs in the develop scene directly, unless you want the prefab instance to have overrides.






On This Page