- Home /
Expandable items in ScriptableObject?
Is it possible to create a ScriptableObject type that has assets nested inside it, that behave similarly to imported mesh files or 'multiple' sprites like in the image attached?
Answer by Bunny83 · Nov 15, 2017 at 10:12 PM
Yes and no.
First about the Yes. You can use AssetDatabase.AddObjectToAsset to add arbitrary assets to the same ".asset" file. Unfortunately (this is the no) you can't control which of the assets is the "main" asset which will show up as root. Generally if you add a built-in type (Mesh, Material, ...) to such an asset, the built in type will become the root and your scriptableobject will become a "nested child".
Technically there's no hierarchy inside an .asset file (just open it with a text editor when you set your asset serialization mode to force text). As far as i know if no particular asset takes precedence it usually shows the first asset in the asset file as main asset. Though there's not really a way to sort them manually. This is still a very annoying behaviour.
Though what does work is adding additional assets which have "hide in hierarchy" set in their hideflags. However those child assets won't show up in the hierarchy of course ^^. They can still be found and linked to but you don't see them or can select them manually, only through scripting.
Your answer

Follow this Question
Related Questions
"Type mismatch" in Inspector for GameObject type in asset file 2 Answers
Prefab as a subasset of a ScriptableObject 0 Answers
AssetDatabase.LoadAssetAtPath() not working after any sort of project change. 0 Answers
Removing invalid objects under asset 0 Answers
Single Scriptable Object Asset 1 Answer