Multiple Nested ScriptableObjects
Asked Answered
I

1

0

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

163861-so.png

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?

Interdental answered 12/4 at 12:25 Comment(1)

Anyone? Im need it too! if you already solved pls tellme your soluction!

Sequester
G
0

For some reason it is impossible. Unity simple doesn’t allow having multiple nesting levels for ScriptableObjects.

If you add “Sub Child” to “Child” you will have “Sub Child” under “Child”.
And if you than add “Child” to “Parent” you will have “Sub Child” and “Child” under “Parent” at the same level.

Griddlecake answered 26/10, 2022 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.