- Home /
Question about prefabs
Hello Human Beings,
When I import a model into Unity I get the imported model not as perfab. When I make the model a prefab, does it copy its mesh or does it get it each time from the original copy of the model?
What I mean is, o I need to have both the model and the prefab? if so, why?
Thanks in advance, Ethan
Answer by Bunny83 · Oct 02, 2017 at 10:02 AM
You have to understand a fundamental concept here. In a Unity Project you have Assets. Assets is any kind of data that is stored on disk inside the Project View. When you import a model / mesh Unity actually creates a special read-only prefab asset in place of the model file. The imported mesh data, the bone structure, animations and other things that might be defined inside the model file get created as sub-assets below the root prefab. The prefab itself is almost like a normal prefab. So it's a serialized gameobject tree with some components.
Those components now will reference other assets like the imported "Mesh", the animations but also other standalone assets such as a "Material" asset.
The model asset is read only because the whole prefab got created by the model importer. When the model gets updated outside Untiy that prefab need to be reimported and might change.
When you create a new seperate prefab out of the imported model prefab, you basically create a copy of the gameobject structure and it's components. However those components will still reference the actual assets (like the Mesh, AnimationClips and Materials).
So yes, of course you have to keep the model asset in your project if you want to use that model. However keep in mind when you build your game Unity only includes "used" assets. So if you do not directly use the imported model prefab but only your own prefab, Unity will only include your prefab and the Mesh and Material assets which your prefab references.
You can simply check which asset are used by your prefab by doing a single left click onto the "Mesh" field of the MeshFilter component of your prefab (or of the SkinnedMeshRenderer depending if you have animations or not). Unity will try to "ping" / highlight the referenced object in the project view.
So creating 10 different prefabs of the same model won't duplicate the actual mesh data. All prefabs would reference the same Mesh object which "lives" as sub asset below the imported model prefab.
Your answer
Follow this Question
Related Questions
Models for game 1 Answer
Pre-Normalized cube model? 3 Answers
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers