How Unity Converts glTF to Prefabs and Meshes

Unity converts glTF (GL Transmission Format) and GLB files into native engine assets through an import pipeline that parses the source data, reconstructs 3D geometry into UnityEngine.Mesh objects, translates PBR materials, and packages the resulting hierarchy into a standard Unity Prefab. Because Unity does not support glTF natively in its base install, this conversion relies on specialized importer packages—such as Unity's official glTFast package or the open-source UnityGLTF—leveraging the engine's ScriptedImporter API to translate raw file buffers into editor-ready assets seamlessly during import time or runtime.

The Role of ScriptedImporter

The conversion process begins with Unity's ScriptedImporter framework. When a .gltf (JSON-based) or .glb (binary) file is placed into the Unity Project folder, the importer registers the file extension and triggers an import task. The importer reads the underlying data structures, isolates the components (geometry, textures, materials, and animations), and declares what native Unity assets will be generated as main and sub-assets inside the project database.

Parsing Structure and Binary Buffers

glTF assets define their scenes using a strict JSON schema coupled with binary blobs (buffers). Conversion happens in the following sequence:

  1. Reading Accessors and Buffer Views: The importer evaluates the JSON file to locate accessor objects, which describe how to interpret raw binary data.
  2. De-interleaving Vertex Data: The importer reads array buffers to extract vertex attributes including positions, vertex colors, UV coordinates, normals, and tangents.
  3. Index Parsing: Index buffers are read to assemble the polygon topology (typically triangle lists) required for rendering.

Converting Geometry to UnityEngine.Mesh

Once raw vertex and index data are isolated, the importer constructs one or more UnityEngine.Mesh instances:

  • Vertex Allocation: Data is packed into native memory buffers and assigned to the mesh via Mesh.SetVertices(), Mesh.SetNormals(), Mesh.SetTangents(), and Mesh.SetUVs(). For high-performance conversion, packages like glTFast write directly into Unity's vertex buffers using Mesh.SetVertexBufferData and the C# Job System.
  • SubMeshes and Topologies: Each glTF primitive corresponds to a sub-mesh in Unity. The importer maps primitive draw modes to Unity's MeshTopology.Triangles.
  • Skinning Data: If the model includes a skinned mesh, the importer reads joint indices and weights, mapping them to Unity's BoneWeight structs or native bone weight buffers, alongside bindposes (inverse bind matrices).

Translating Materials and Textures

glTF utilizes a standard Metallic-Roughness or Specular-Glossiness Physically Based Rendering (PBR) workflow. Unity maps these definitions to corresponding shader properties:

  • Texture Decoding: Images embedded or referenced by the glTF file are decoded into Texture2D instances. Normal maps and occlusion/roughness/metallic (ORM) packed textures are remapped to match the channel layouts expected by Unity's Standard, Universal Render Pipeline (URP), or High Definition Render Pipeline (HDRP) shaders.
  • Material Mapping: A native UnityEngine.Material is created for each glTF material definition. The importer assigns base color factors, metallic and roughness values, emission, and normal scale factors directly to the target shader's uniform parameters.

Hierarchy Construction and Prefab Generation

After generating meshes and materials, the importer constructs the object graph:

  1. Transform Nodes: glTF scenes are organized as directed acyclic graphs of nodes. The importer iterates through these nodes, instantiating a GameObject for each and setting its local position, rotation, and scale.
  2. Component Assignment: Nodes containing geometry are assigned a MeshFilter (referencing the newly created Mesh) and a MeshRenderer (referencing the generated Material). Skinned nodes receive a SkinnedMeshRenderer with associated transform references for the bone rig.
  3. Animation Clips: glTF animation channels (translation, rotation, scale, and morph weights) are converted into AnimationClip curves mapped to the instantiated node paths.
  4. Serialization: The entire root GameObject hierarchy, along with its dependent child meshes, materials, and animation clips, is passed to the AssetImportContext. Unity serializes this root object as a standard Prefab asset, making it directly usable in scenes or via script instantiation.