I think it’s impossible, but I’d really like to do something like that.
This is not possible.
It is possible to add a ScriptableObject as a sub-asset to a prefab
Well, I’m sad, but thanks. Good to know that though. I don’t think I’ve ever tried it, will keep it in mind.
I don’t seem to be able to do that. Here’s the code
var area = CreateInstance<AreaDataSO>();
area.name = "SubAsset";
AssetDatabase.AddObjectToAsset(area, Selection.activeObject);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(area));
It just adds a scriptable object to what I select and it works on other scriptable objects but not on prefabs.
This should work
var area = CreateInstance<AreaDataSO>();
area.name = "SubAsset";
AssetDatabase.AddObjectToAsset(area, Selection.activeObject);
if (prefab)
PrefabUtility.SavePrefabAsset(Selection.activeObject)
After adding an object to the prefab you need to save prefab again in order for that file in the assets folder to be updated.
1 Like
This is crahing editor
Can you post full working example please?