- Home /
How can I create a prefab variant in C# script?
I am trying out Unity's new prefab workflow. I want to programmatically create prefab variant(s) on an prefab I've already created. I am using Unity 2018.3.0b7. How can this be done?
Answer by ecv80 · Nov 01, 2018 at 08:07 AM
During current run:
Instantiate the prefab off-screen
Make the relevant changes to the new instance
Keep a reference to this instance so as to make new instances from it on-wards
Making it permanent:
Instantiate the prefab off-screen
Make the relevant changes to the new instance
Use
UnityEditor.PrefabUtility.CreatePrefab("Assets/Resources/...", gameObjectInstance)
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html https://docs.unity3d.com/ScriptReference/PrefabUtility.CreatePrefab.html
As a side note: CreatePrefab was updated to "PrefabUtility.SaveAsPrefabAsset"
Your answer
![](https://koobas.hobune.stream/wayback/20220612181332im_/https://answers.unity.com/themes/thub/images/avi.jpg)