If you want to use GLB or glTF files in Unity, the easiest solution is Unity’s official glTFast package. It adds Editor importing as well as runtime loading of glTF 2.0 models.
This is particularly useful for AI-generated 3D models. Many current tools produce
|
1 |
.glb |
as their primary format, as discussed in our AI 3D model generation for Godot and Unity guide.
This guide walks through the complete Unity glTFast setup: installing the package, importing your first GLB, loading models at runtime, enabling compressed models, and avoiding a few easy-to-miss build problems.
What Is glTFast?
glTFast is Unity’s package for importing and exporting glTF 2.0 files.
It supports the two formats you will normally encounter:
-
– a binary glTF file that can contain geometry, materials, textures and animations in one file.1.glb
-
– a JSON-based glTF file that may reference separate1.gltfbuffers and image files.1.bin
For most workflows, I recommend GLB. Having the mesh, materials and textures packaged into one file avoids broken relative paths and makes moving assets between tools much easier.
Current glTFast releases require Unity 2021.3.46f1 or newer.
Install Unity glTFast
You do not need to download glTFast manually from GitHub. It can be installed directly through Unity’s Package Manager.
- Open your Unity project.
- Go to Window > Package Manager.
- Click the + button.
- Select Add package by name.
- Enter the package name:
|
1 |
com.unity.cloud.gltfast |
Leave the version field empty unless you intentionally want to install a particular version, then click Add.
Unity downloads glTFast and its required dependencies through the Package Manager.
Note: Older tutorials may refer to
|
1 |
com.atteneder.gltfast |
. That was the original package identifier before glTFast became an official Unity package. For a new project, use
|
1 |
com.unity.cloud.gltfast |
.
Verify the Installation
The quickest way to check that glTFast is working is to import a GLB file.
- Find a
file.1.glb
- Drag it into your project’s Assets folder.
- Select it in the Project window.
glTFast should import the file automatically.
You can expand the imported asset in the Project window to inspect its scenes, meshes, materials, textures and animations.
You can then drag the imported asset into your Unity scene like other Unity assets.
Importing .gltf Files
Plain
|
1 |
.gltf |
files work as well, but remember that they may depend on additional files.
A model directory might look like this:
|
1 2 3 4 5 6 |
Robot/ |-- robot.gltf |-- robot.bin |-- basecolor.png |-- normal.png `-- metallic.png |
Copy the complete set of files into Unity and keep their relative paths intact.
Moving only
|
1 |
robot.gltf |
can result in missing geometry or textures if the referenced resources cannot be found.
This is one reason GLB is generally more convenient when moving AI-generated models into Unity.
Load a GLB or glTF at Runtime
Editor import is useful when the model is already known while building your application.
glTF becomes even more interesting when models need to be downloaded or selected at runtime.
glTFast provides two main approaches.
Option 1: GltfAsset Component
Create an empty GameObject and add the GltfAsset component.
The component provides settings for loading and instantiating a glTF asset.
You can also add it from code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
using GLTFast; using UnityEngine; public class GltfAssetLoader : MonoBehaviour { private void Start() { var gltf = gameObject.AddComponent<GltfAsset>(); gltf.Url = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf"; } } |
The URL in this example points to the Khronos glTF sample Duck model. It is useful for verifying that runtime loading works before testing your own assets.
Option 2: Load with GltfImport
If you need more control over loading and instantiation, use
|
1 |
GltfImport |
directly.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
using GLTFast; using UnityEngine; public class RuntimeGltfLoader : MonoBehaviour { [SerializeField] private string modelUrl = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF/Duck.gltf"; private async void Start() { var gltf = new GltfImport(); bool success = await gltf.Load(modelUrl); if (success) { await gltf.InstantiateMainSceneAsync(transform); } else { Debug.LogError("Loading glTF failed."); } } } |
Attach this script to an empty GameObject.
Once the sample model works, replace
|
1 |
modelUrl |
with the URL of your own GLB or glTF model.
|
1 |
GltfImport |
is useful when you want to control loading yourself, customize import options, inspect the imported data, or instantiate a loaded model multiple times.
Loading Local glTF Files at Runtime
glTFast can also load models from local files.
When supplying a local filesystem path through Unity’s web request infrastructure, you may need to use a
|
1 |
file:// |
URI.
For example:
|
1 |
file:///C:/Models/robot.glb |
Filesystem behavior differs between target platforms, so files shipped with your application should be handled according to Unity’s platform-specific file and StreamingAssets rules.
Draco, KTX and Meshoptimizer Support
Modern GLB files may use additional compression extensions.
This is especially common with models optimized for web delivery or produced by automated 3D pipelines.
glTFast can use additional Unity packages for formats including:
- Draco –
1KHR_draco_mesh_compression
- KTX/Basis Universal –
1KHR_texture_basisu
- meshoptimizer –
1EXT_meshopt_compression
You do not necessarily need all of these packages.
Install them when the GLB files you want to load actually use the corresponding extension.
If a normal GLB works but a compressed GLB fails to load, checking which glTF extensions the file uses should be one of your first troubleshooting steps.
Important: Shader Variants in Builds
There is one problem that is particularly easy to miss:
Your glTF model can look correct inside the Unity Editor and still have broken or pink materials in the final build.
glTFast creates materials using different shaders and shader variants depending on the properties contained in the glTF material.
Unity can make the appropriate shaders available while working in the Editor, but shader variants that appear unused may be stripped from a player build.
This matters especially when the glTF models are only downloaded at runtime.
If your application loads models dynamically, test an actual player build before shipping.
Create a Shader Variant Collection
If you know the types of models your application will load, you can collect their required shader variants.
- Run a scene in the Editor that loads representative glTF models.
- Open Edit > Project Settings > Graphics.
- Find the Shader Preloading section.
- Save the currently tracked shader variants to a
.1ShaderVariantCollection
- Add the resulting collection to Preloaded Shaders.
This helps ensure that shaders required by runtime-created glTF materials are also included in the final build.
Do not test runtime importing only inside the Editor and assume the standalone build will behave identically.
Using Runtime Meshes with Physics
glTFast normally uploads imported mesh data for rendering and can discard CPU-side mesh data afterwards to reduce memory usage.
That is a good default for rendering, but it can be a problem if you later need CPU access to the mesh.
This can matter for certain physics, collider, mesh processing or geometry operations.
If you need imported meshes to remain readable, glTFast provides the following scripting define:
|
1 |
GLTFAST_KEEP_MESH_DATA |
Add it to your project’s scripting define symbols.
Only enable this if you actually need CPU-readable mesh data, because retaining the additional data increases memory usage.
Loading Untrusted glTF Files
If your application accepts arbitrary models from users or external services, glTFast provides an additional validation mode.
Add the following scripting define:
|
1 |
GLTFAST_SAFE |
This enables additional validation when processing potentially malformed input.
The additional checks come with some performance overhead, which is why they are not necessarily required for a fixed set of models that you control and test yourself.
For applications that allow users to upload arbitrary glTF or GLB files, enabling the additional checks is worth considering.
Common glTFast Problems
GLB or glTF Does Not Import
Open Unity’s Package Manager and confirm that
|
1 |
com.unity.cloud.gltfast |
is installed.
Also check the Unity Console for import errors.
Textures Are Missing from a .gltf File
Make sure you copied the external textures and
|
1 |
.bin |
files together with the
|
1 |
.gltf |
file.
Do not change their relative directory structure unless you also update the corresponding URIs inside the glTF file.
The Model Works in the Editor but Materials Break in the Build
Check Unity’s shader stripping.
Create a
|
1 |
ShaderVariantCollection |
containing the shader variants required by your runtime-loaded models and include it in the build.
A Compressed GLB Fails to Load
Check whether the model uses Draco, KTX/Basis Universal or meshoptimizer compression.
If it does, install the corresponding optional Unity package.
A Local Runtime File Cannot Be Found
Check the path and whether a
|
1 |
file:// |
URI is required.
Also verify the filesystem and StreamingAssets rules for the platform you are building for.
MeshCollider or CPU Mesh Processing Does Not Work
If your code needs the imported mesh to remain CPU-readable, add:
|
1 |
GLTFAST_KEEP_MESH_DATA |
Recommended Unity glTFast Workflow
For most projects, the setup is straightforward:
- Install
.1com.unity.cloud.gltfast
- Prefer
over multipart1.glbassets where practical.1.gltf
- Import fixed game assets into the Unity project at design time.
- Use
or1GltfAssetfor models that must be loaded dynamically.1GltfImport
- Install Draco, KTX or meshoptimizer support only when your models require it.
- Test runtime-loaded materials in an actual player build.
- Make sure the necessary shader variants are included before release.
Final Thoughts
Unity’s glTFast package removes most of the friction involved in working with GLB and glTF files inside Unity.
Once installed, you can import GLB files directly into a project or load them dynamically while the application is running.
This makes glTFast particularly useful for modern AI 3D workflows. Tools and pipelines that generate GLB output can feed their results directly into a Unity application without requiring an FBX conversion step first.
The main thing I would not skip is testing a real player build.
Runtime loading itself is relatively straightforward. Shader stripping is the issue most likely to produce the classic “works in the Editor” surprise.
With that handled, GLB is a convenient format for bringing generated and externally supplied 3D models into Unity.
Happy creating!