So, I have a prefab, I want to make variants of it by code and add them to the scene. Any ideas?
I’m gonna guess it’s some combination of calls in this editor class:
Yeah, I know the prefab utility, and I know that you can create a prefab by using PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, localPath, InteractionMode.UserAction);
But what about variants? In my case I already have the prefab.
I’ve been thinking maybe of passing the prefab as the connect parameter, but not sure what it’ll make out of it.
It might be just loading the base prefab, making changes, then making a fresh prefab and it knows to make the variant because it started from another? Honestly I haven’t done much with the variants stuff yet even in the editor, let alone tracking down the scripting way.
I’m gonna keep exploring to see if I find a way to do it, but hopefully someone has done something of the sort and will enlight me a bit. Thanks anyway.
I think I found the solution in another post. It’s like this, any critiques are welcome, (local path is a unique path created in my code, you’d have to create your own to use it). Thanks Kurt for all your support.
var instanceRoot = PrefabUtility.InstantiatePrefab (prefabOriginal) as GameObject;
var variantRoot = PrefabUtility.SaveAsPrefabAsset (instanceRoot, localPath);
For some reason t his doesn’t seem to work for me, it creates a new prefab, and then it creates variants of it, but I don’t want a new base prefab every time I use the thing