I’m having a hard time with nested ScriptableObjects. I’ve tried everything I can think of, but I can’t seem to add a ScriptableObject asset to another one. Here’s one of the many things I’ve tried:
private ChildClass AddNewChild (Object database) {
ChildClass newChild = CreateInstance<ChildClass> (); //Derives from ScriptableObject
newChild.hideFlags = HideFlags.HideInHierarchy;
AssetDatabase.CreateAsset (newChild, AssetDatabase.GenerateUniqueAssetPath ("Assets/New Child.asset"));
AssetDatabase.AddObjectToAsset (newChild, database); //Database is also a ScriptableObject asset.
AssetDatabase.SaveAssets ();
AssetDatabase.Refresh ();
return newChild;
}
No matter what I do or how I call or arrange these lines, it always throws an error at the AddObjectToAsset function.
"Couldn’t add object to asset file because the MonoBehaviour ‘New Child’ is already an asset at ‘Assets/New Child.asset’!
I could have sworn I was able to nest ScriptableObjects before… What am I doing wrong?