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?