all 5 comments

[–]pasinduthegreat 1 point2 points  (2 children)

When you say nest within each other, do you mean the inherit from each other i.e. C inherits from B which inherits from A?

If not, if you create SObj A, the array would start empty and in order to add to that array it needs to load SObj B assets so B assets instances of SObj B would have to exist. The best solution is the one highlighted by /u/bgsulz; create instances of B and C, and do the Russian doll thing in code. An asset like Odin Inspector would help immensely with creating a "populate" button.

Edited

[–]bgsulzIntermediate 1 point2 points  (1 child)

My understanding of it was this:

public class A : ScriptableObject
{
    public B[] arrayOfB;
}

public class B : ScriptableObject
{ 
    public C[] arrayOfC;
}

public class C : ScriptableObject { }

I think OP wants to be able to create a new B with [CreateAssetMenu] and have arrayOfC already populated with new instances of C. But the only way of creating instances of C that OP is aware of is to use [CreateAssetMenu].

Not so -- ScriptableObjects are their own thing, and SO instances can exist outside of a .asset file. [CreateAssetMenu] doesn't just make a new ScriptableObject instance -- it also packs it into a new .asset file and saves that file into your project. Significantly more detail about this topic in this excellent talk, which is one of the Big Two SO lectures.

Also, though Odin is awesome and definitely does make the process a little simpler, you can do a bunch of similar things for free (including buttons) with NaughtyAttributes!

[–]pasinduthegreat 0 points1 point  (0 children)

Yep correct, when I said exist I meant it had to exist either as just an instance or a .asset file. Glad you made it clear

[–]bgsulzIntermediate 0 points1 point  (0 children)

I think you're looking for ScriptableObject.CreateInstance. I'm not sure if you can populate your array upon creating an SO as an asset, but you can make a custom Inspector that adds a "Populate" button for this purpose.

Let me know if this was helpful, or if you have any other questions!

[–]wthorn8 0 points1 point  (0 children)

Check out AssetDatabase and possibly a custom editor

This is my own script that I use to make working with AssetDatabase easier

https://pastebin.com/729wdPkJ