Quick answer: Open the Variant in Prefab Mode (double-click the .prefab asset) to add components onto the variant itself. From a scene instance, Add Component places the component as an instance override which can fail in some configurations.
Here is how to fix Unity errors or unexpected behavior when adding a component to a Prefab Variant. Variants have a specific edit mode for adding their own components vs overriding inherited ones.
The Symptom
Right-click on a variant scene instance and Add Component. Unity warns or silently does not persist. Or you add it but on next reload the component is missing from the variant asset.
What Causes This
Wrong edit context. Adding from a scene instance creates an instance override that is sometimes confusing. Adding from Prefab Mode adds to the variant itself.
Missing parent component. A variant inherits from a parent prefab; some component additions need the parent to have related setup.
Component restrictions. Some scripts have RequireComponent that interacts with inheritance unexpectedly.
The Fix
Step 1: Open Prefab Mode for the variant. In Project window, double-click the variant .prefab. The Hierarchy switches to Prefab Mode showing the variant’s contents.
Step 2: Add Component while in Prefab Mode. Components added here belong to the variant; they appear on every instance of the variant. Save with Ctrl-S before exiting.
Step 3: Override values vs add components.
From scene instance:
- Override property values: Yes (most fields)
- Add new component: Becomes an override; may need Apply
- Remove inherited component: No
From Prefab Mode (variant):
- Add component to variant: Yes
- Override property values: Yes
- Remove inherited component: Cannot - inherited from parent
Step 4: For removing inherited components. Disable on the variant (set enabled = false) instead. Or fork: create a new variant with a different parent that does not have the component.
Step 5: Use Add Component via script.
[UnityEditor.MenuItem("Tools/Add Component To Variant")]
static void AddCompTo()
{
var path = AssetDatabase.GetAssetPath(Selection.activeObject);
var root = PrefabUtility.LoadPrefabContents(path);
root.AddComponent<Rigidbody>();
PrefabUtility.SaveAsPrefabAsset(root, path);
PrefabUtility.UnloadPrefabContents(root);
}
Programmatic additions bypass UI quirks for batch operations.
“Variant in Prefab Mode for additions. Disable cannot replace remove. Programmatic for batches.”
Related Issues
For prefab apply confusion, see Apply All Confusion. For Prefab Mode save, see Prefab Stage Save.
Open variant in Prefab Mode. Add components there. Save before exiting. Components persist.