Save Prefab Variant at runtime?

I need to, at runtime, save a prefab I created, but as a variant.
I tried this line:

PrefabUtility.SaveAsPrefabAsset(myPrefabGameobjectCreatedAtRuntime, localPath);

But this saves a new base prefab.

This is the only way I know to make a prefab variant:

Object originalPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject));
GameObject objSource = PrefabUtility.InstantiatePrefab(originalPrefab) as GameObject;   
GameObject prefabVariant = PrefabUtility.SaveAsPrefabAsset(objSource, localPath);

But this only works loading the original prefab from a folder (not a prefabinstance made runtime).
Any suggestions?

1 Like

You cannot make prefabs at runtime. It is impossible, all the api calls are editor only.

Why would you need to make a prefab at runtime?

1 Like