I’m trying to create nested ScriptableObjects. So far I can add a child ScriptableObject to a parent object using AssetDatabase.AddObjectToAsset which is good. However, attempting to add a sub child object to the child adds the sub child to the parent instead. This is the code I’m using:
public void CreateNestedStructure()
{
var parent = CreateInstance<ScriptableObject>();
parent.name = "Parent";
AssetDatabase.CreateAsset(parent, "Assets/Parent.asset");
var child = CreateInstance<ScriptableObject>();
child.name = "Child";
AssetDatabase.AddObjectToAsset(child, parent);
var subChild = CreateInstance<ScriptableObject>();
subChild.name = "Sub Child";
AssetDatabase.AddObjectToAsset(subChild, child);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
This is the result
I wish to have the Sub Child reside inside Child, to make the file structure more organized. I assume the problem is that Child is an object of the Parent asset and not an asset itself. Is it possible to achieve this structure somehow?