Skip to content

Prefabs, variants and overrides

↑

A Prefab asset stores a reusable GameObject hierarchy, components and serialized values. A Prefab instance is an occurrence of that asset in a scene or created at runtime. Updating the asset normally propagates to instances unless a property was explicitly overridden.

Overrides keep one instance different, while Prefab Variants derive a reusable variation from a base prefab. Nested Prefabs let one prefab include another. Use a variant for an enemy with different speed or appearance rather than duplicating an entire complex hierarchy.

EnemySpawner.cs
using UnityEngine;
public sealed class EnemySpawner : MonoBehaviour
{
[SerializeField] private GameObject enemyPrefab;
[SerializeField] private Transform spawnPoint;
public void Spawn()
{
if (enemyPrefab == null || spawnPoint == null) return;
Instantiate(enemyPrefab, spawnPoint.position, spawnPoint.rotation);
}
}

When: Repeated enemies, UI widgets, loot or projectiles. Pitfall: Changing a scene instance may create an override instead of updating the source asset. Always inspect override status before applying/reverting. At high spawn rates consider pooling rather than repeatedly instantiating/destroying objects.

Try it: Make a base enemy prefab and a variant with a different serialized speed. Change the common renderer in the base and inspect both instances.