- Home /
Question by
bloxxyyy · Jan 18 at 05:30 PM ·
programmingprefab-instance
How does unity add a scriptable object as a child of a prefab
I have been looking at how unity has been adding scriptable objects to prefabs however both the AssetDatabase.AddObjectToAsset and PrefabUtility object don't seem to work here. Anyone knows how to do this in code?
Example code:
var go = new GameObject();
var prefabPath = path + "/" + palleteName + ".prefab";
PrefabUtility.SaveAsPrefabAsset(go, prefabPath);
var gridPallete = CreateInstance(typeof(GridPalette)) as GridPalette;
gridPallete.name = "Pallete Settings";
AssetDatabase.AddObjectToAsset(gridPallete, prefabPath);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(gridPallete));
AssetDatabase.Refresh();
note: This is for an editor script. Trying to create Palletes from code.
image.png
(5.1 kB)
Comment