Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Models vs prefabs

Discussion in 'Editor & General Support' started by Eranekao, Jan 1, 2018.

  1. Eranekao

    Eranekao

    Joined:
    Oct 4, 2015
    Posts:
    2
    When I export a single object as an FBX with Blender and import it in Unity (without materials, rig or animations), there appears to be two different parts to the fbx in the browser tab. First is the FBX container itself, whose name is the file name of the FBX. Second, if you click on the arrow on the FBX thumbnail, there is the mesh itself, whose name is the object name within Blender before export.

    If you drag just that second part (the mesh) into the scene, it appears bright pink (no material assigned) and the object name is in black in the hierarchy window. However, if you drag the FBX file in the scene, the following happens:

    * The default material is assigned to the mesh
    * Its name appears in BLUE in the hierarchy window, as if it were a prefab. If you right click it, there is even the option "Select prefab"
    * There is a set of options as well as the mention "model" (where the mention "prefab" usually is) in the top section of the inspector when the object is selected (see picture). The options are the same as with a prefab, but instead of "apply" there is "open" and the "revert" option doesn't seem to do anything.



    It is also possible to make a prefab out of these two different "types" of objects.

    So, dragging the FBX "container" instead of the mesh creates an object which shares characteristics with a prefab, althought it isn't one. What is that about and where is it documented? What is the difference between the two in terms of workflow? Also, would there be any difference between a prefab that is made with the FBX "container" vs one made with the mesh only? I couldn't find anything about it in the documentation.

    Thanks,
     
    reevthechameleon and Harinezumi like this.
  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,294
    It's actually a pseudo-prefab type. If you check PrefabUtility.GetPrefabType for the object, you get ModelPrefabInstance.

    There isn't much to it - select and revert does the same as for a prefab, but Open opens it in whatever program is set to edit the file type. It's conceptually... somewhat like Apply, I guess?

    If you want the object to be a real prefab, just drag it into the scene, and drag it from the scene into the project window.
     
    donaldshen likes this.
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    It shares some characteristics of a prefab, however it lacks the single most important part of prefabs, the ability to make and apply changes to the original and have those changes propagate. Import settings can be altered, but everything else is baked.

    Practically speaking, just treat it like an image or any other source asset. It’s contents are applied to game objects, which happens automatically when you drag it into scene (like a sprite). As @Baste pointed out, if you want a proper prefab, drag it back into the project and use that.
     
    donaldshen likes this.
  5. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    be careful when making it a prefab, if a model has multiple nodes as some do when animated etc and if those node transforms change, the transforms will not be updated inside a prefab made from that model. You will then need to recreate the prefab. I tend to instantiate models at runtime or create an editor script to allow for fast and easy updating of models used in prefabs where complex hierarchies exist.
     
    efge, Harinezumi and zombiegorilla like this.
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    Indeed. In that case you want to be aware of that and take care not to tweak the positions, or to not rely on them. In those instances I prefer the editor scripting (tooling/pipeline approach).