Quick answer: Instantiate was handed a null reference. The prefab field was never assigned (or only on one scene instance, not on the prefab asset), an array slot is empty, Resources.Load returned null for a wrong path, or an Addressables or AssetBundle load had not finished. Find the line from the stack trace, assign or correctly load the prefab, and check for null with a log that names the field before you instantiate.
The game tries to spawn an enemy, a bullet or a UI panel and the log shows an ArgumentException from Instantiate instead. The exception is honest about what happened, since the thing you asked Unity to copy was null, and silent about which reference that was and why it was empty. It also has an awkward habit: the same mistake goes by a different exception name in the editor, so many teams first see this exact message in a build or in a player’s log. This guide covers the causes, how to pin down the reference, the fixes with code, and why some players hit it when you never do.
- The exact error
- One empty slot, three exception names
- What causes it
- How to find which reference it was
- Fix 1: assign the prefab on the asset
- Fix 2: check before instantiating, and name the field
- Fix 3: load correctly, and wait for the load
- Fix 4: stop using scene objects as templates, and pool
- Why only builds, and only some players
- How to confirm the fix
- Seeing it from players’ builds
- Related guides
- Frequently asked questions
The exact error
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at <...>:0)
EnemySpawner.Spawn () (at Assets/Scripts/EnemySpawner.cs:31)
The first line is fixed. Where this page shows <...>, Unity prints a long hex id. The UnityEngine.Object frames under the message vary with the overload you called and the Unity version (there is often a CheckNullArgument frame), and the first frame that names your own class is where to look. Older Unity versions worded the message “The thing you want to instantiate is null”.
Instantiate checks its first argument before doing anything else and throws when it is a real C# null. Nothing is spawned, and the rest of the calling method does not run.
One empty slot, three exception names
Which exception you get for an empty prefab reference depends on how it became empty and where the code runs.
| Exception | When you see it |
|---|---|
ArgumentException: The Object you want to instantiate is null. | The reference is a real null: a variable code never set, a failed load, or an empty Inspector slot in a build. |
UnassignedReferenceException | Editor only. An Inspector field left at None. The editor fills such fields with a placeholder so it can name the variable for you. |
MissingReferenceException | In the editor, when the object you pass existed once and was destroyed, or its asset is gone. |
NullReferenceException | Your own code touched the null reference first, for example prefab.name or spawnPoint.position on the same line. |
The practical consequence: an unassigned prefab that you would recognise in the editor as an UnassignedReferenceException shows up in a player build as the ArgumentException on this page. They are the same bug. For a destroyed original in a player build, the exception type differs between Unity versions, so do not rely on it; the guard in Fix 2 catches both.
What causes it
- The prefab field was never assigned. A
public GameObject enemyPrefab;still showing None in the Inspector on the object that runs the code. - It is assigned on a scene instance and not on the prefab asset. You dragged the reference onto the spawner in one scene. The spawner prefab itself, every other scene, and every copy spawned at runtime still have None.
- An empty slot in an array or list. The size was raised to 6 and five prefabs were dragged in.
enemies[Random.Range(0, enemies.Length)]picks the empty one now and then. Resources.Loadreturned null. The path includesAssets/Resources/or the.prefabextension, the asset is not under a folder namedResources, or the type argument does not match the asset.- An asynchronous load has not completed, or failed. An Addressables handle’s
Resultis null until the operation finishes and stays null if it fails.AssetBundle.LoadAssetreturns null for a name that is not in the bundle. - A lookup in your own code returned null:
GameObject.Findon an inactive or absent object, a dictionary fallback, a field another script was supposed to set first. - The reference broke. The prefab was renamed, moved or deleted outside Unity without its
.metafile, and the slot now reads Missing. See missing .meta files and broken prefab references. - A scene object used as a template. The “prefab” is an object in the Hierarchy. It goes away on a scene change, or its own
Destroy(gameObject, 3f)removes it three seconds in. - The asset is not in the build. It was loaded through
AssetDatabaseinside#if UNITY_EDITOR, moved out ofResources, or lives in bundles that were not built for this platform.
The first three are by far the most common in small projects. Causes 5 and 9 dominate once a game loads content at runtime.
How to find which reference it was
Open the line the stack trace names. In the editor and in development builds the trace includes the file and line number. Release builds usually give the method name without a line, which is enough when the method has one Instantiate call.
If that line indexes an array, or the script is on many objects, the trace cannot tell you which slot or which object. Add a temporary log directly above it:
Debug.Log($"Spawn on '{name}': index {index} of {enemies.Length}, prefab = {enemies[index]}", this);
Passing this as the second argument makes the Console entry clickable: one click highlights the object in the Hierarchy. To inspect every object that carries the script, type t:EnemySpawner in the Hierarchy search box and check the slot on each result, then open the prefab asset itself and check it there.
For a player’s report, read their log file. On Windows it is %USERPROFILE%\AppData\LocalLow\CompanyName\ProductName\Player.log. Look at the lines just above the exception for a failed load.
Fix 1: assign the prefab on the asset
Drag the prefab from the Project window, not from the Hierarchy, into the field. If the spawner is itself a prefab, make the assignment stick for every copy: select the instance, open the Overrides dropdown at the top of the Inspector and choose Apply All, or open the prefab in Prefab Mode and assign it there. A bold field label on an instance means the value is an override that exists only on that instance.
For arrays, remove the empty element. Do not leave a None in the middle “for later”.
Fix 2: check before instantiating, and name the field
// Broken
void Spawn()
{
Instantiate(enemyPrefab, spawnPoint.position, spawnPoint.rotation);
}
// Fixed
void Spawn()
{
if (enemyPrefab == null)
{
Debug.LogError($"EnemySpawner on '{name}': enemyPrefab is not assigned", this);
return;
}
Instantiate(enemyPrefab, spawnPoint.position, spawnPoint.rotation);
}
Unity’s == null is true for a real null and for a destroyed object, so this one check covers the editor and build variants. The message gives you the script, the object and the field without a debugger. Catch the mistake earlier still with OnValidate, which runs in the editor whenever a value changes in the Inspector:
void OnValidate()
{
if (enemies == null) return;
for (int i = 0; i < enemies.Length; i++)
{
if (enemies[i] == null)
Debug.LogWarning($"EnemySpawner on '{name}': enemies[{i}] is empty", this);
}
}
Fix 3: load correctly, and wait for the load
Resources.Load takes a path relative to a folder named Resources, with forward slashes and no extension:
// Broken: returns null, then Instantiate throws
GameObject prefab = Resources.Load<GameObject>("Assets/Resources/Enemies/Grunt.prefab");
Instantiate(prefab);
// Fixed: the file is Assets/Resources/Enemies/Grunt.prefab
GameObject prefab = Resources.Load<GameObject>("Enemies/Grunt");
if (prefab == null)
{
Debug.LogError("No GameObject at Resources path 'Enemies/Grunt'");
return;
}
Instantiate(prefab);
The type argument has to match too: asking for a GameObject at a path that holds a ScriptableObject or a material returns null. More cases are in Resources.Load returning null.
With Addressables, the handle exists immediately and the asset does not:
// Broken: Result is still null on this line
var handle = Addressables.LoadAssetAsync<GameObject>("Enemies/Grunt");
Instantiate(handle.Result);
// Fixed
private AsyncOperationHandle<GameObject> handle;
private GameObject enemyPrefab;
IEnumerator Start()
{
handle = Addressables.LoadAssetAsync<GameObject>("Enemies/Grunt");
yield return handle;
if (handle.Status != AsyncOperationStatus.Succeeded)
{
Debug.LogError($"Failed to load 'Enemies/Grunt': {handle.OperationException}", this);
yield break;
}
enemyPrefab = handle.Result;
}
void OnDestroy()
{
if (handle.IsValid()) Addressables.Release(handle);
}
This needs using UnityEngine.AddressableAssets; and using UnityEngine.ResourceManagement.AsyncOperations;. Anything that spawns before enemyPrefab is set still needs the guard from Fix 2, or keep the spawner disabled until the load succeeds. Decide what the game does when the load fails: retry, show a message, or skip that enemy. A failed load on a player’s connection should not end in an exception.
Fix 4: stop using scene objects as templates, and pool
Make the template a prefab asset. An asset is never destroyed by a scene change or by a script running on a copy of it. If the spawner must survive scene loads, references to assets survive with it; references to objects in the old scene do not.
For anything spawned often, a pool also gives you a single place to validate the prefab. Unity ships one in UnityEngine.Pool:
private ObjectPool<GameObject> pool;
void Awake()
{
if (bulletPrefab == null)
{
Debug.LogError($"BulletPool on '{name}': bulletPrefab is not assigned", this);
enabled = false;
return;
}
pool = new ObjectPool<GameObject>(
createFunc: () => Instantiate(bulletPrefab),
actionOnGet: bullet => bullet.SetActive(true),
actionOnRelease: bullet => bullet.SetActive(false),
actionOnDestroy: bullet => Destroy(bullet),
defaultCapacity: 32);
}
Callers use pool.Get() and pool.Release(bullet) and never call Instantiate themselves. Pooled objects that live in a scene are destroyed with it, so rebuild the pool per scene or parent it under an object marked DontDestroyOnLoad.
Why only builds, and only some players
- The editor uses another name. If you search your logs for this
ArgumentException, the editor’sUnassignedReferenceExceptionfor the same slot does not match. - An empty slot picked at random. One None in a list of twelve fails on roughly one spawn in twelve, which a short playtest can miss.
- Load timing. On your machine the asynchronous load finishes before the first spawn. On a slow disk or connection it does not.
- Remote content failed for that player. They were offline, the download errored, or the bundle for their platform was never uploaded.
- Old save data. A saved id maps to a prefab that no longer exists, the lookup returns null, and the spawn throws. Validate ids at load, as described in the KeyNotFoundException guide.
- A path few people reach: a late level, a rare enemy, a platform-specific prefab.
How to confirm the fix
Test in a build, because the editor reports the unassigned case differently. Use a development build so traces have line numbers. Visit every spawner, and let random spawners run long enough to cycle through their whole list. For runtime-loaded content, start once with a cleared cache and once with the network disabled, and confirm you get your own error message and a working fallback. Then search Player.log for you want to instantiate is null; it should not appear.
Seeing it from players’ builds
This exception mostly happens where you are not looking, so automatic capture is a good fit. The Bugnet Unity SDK listens to Unity’s log callback and files exceptions and error logs with the stack trace, recent log lines, platform, OS and game version, stacking identical titles into one entry. Two limits are worth knowing. A release build’s trace may have no line numbers, and the exception text never names the field, so the report is far more useful when the guard from Fix 2 has logged “enemyPrefab is not assigned” first; that error is filed as well. And Bugnet does not know which asset failed to download for that player. Log the address and the load error yourself, and those lines travel with the report.
Related guides
- How to Fix UnassignedReferenceException in Unity
- How to Fix Resources.Load Returning Null in Unity
- How to Fix “MissingReferenceException: The object of type ‘GameObject’ has been destroyed” in Unity
- Fix: Unity [SerializeField] Reference Is Null After Build
- How to Fix Unity’s NullReferenceException
Frequently asked questions
What does The Object you want to instantiate is null mean?
The first argument passed to Instantiate was null. Unity checks the reference before copying anything and throws an ArgumentException. The prefab variable was never assigned, an asset load returned null, or the slot in an array or list is empty.
Why do I get this error in the build but not in the editor?
In the editor an empty Inspector field holds a placeholder, and using it throws UnassignedReferenceException instead. In a build the field is a real null, so Instantiate throws the ArgumentException. Assets that load in the editor can also be missing from a build.
How do I find which prefab is null?
The stack trace names the script, method and, in development builds, the line. If the line uses an array or the script is on many objects, log the index and the object name just before Instantiate, passing the component as the context so the Console entry highlights the object.
Why does Resources.Load return null for my prefab?
The path must be relative to a folder named Resources, use forward slashes and leave out the file extension. A prefab at Assets/Resources/Enemies/Grunt.prefab loads with the path Enemies/Grunt. The requested type must also match the asset type.
Can I instantiate an Addressables prefab right after calling LoadAssetAsync?
No. The call returns a handle at once and the asset arrives later. Wait for the handle to complete, check that its status is Succeeded, and only then use its Result. Using Result earlier, or after a failed load, passes null to Instantiate.
The exception never names the field, so make your own code name it: one null check with the script, object and field in the message, placed before every Instantiate that takes a loaded or Inspector-assigned prefab.