- Home /
Filling array with Scribtable Objects automaticly?
Is it possible in editor get all specific type of scribtableobjects to array/list automaticly when you are creating them? So it would save hassle of drag and dropping each scribtableobject in inspector.
Example, I create new scribtable object under class LootDrinks to be "Water Bottle", and LootMaster automaticly finds that you created new sciptableobject, so it adds it to LootDrinks[] array.
Answer by eses · Sep 02, 2018 at 08:10 PM
Hi @SolidJuho
So you want to update an inspector list, when you create a new asset file out of some ScriptableObject? You create an asset file out of Item : ScriptableObject, using CreateAssetMenu, or you create an asset from it's subclasses like Banana : Item, Hammer : Item - and these should be added to some inspector Array / List?
Something like this:
Create a custom inspector for your MB that has some list / array.
Get the guids of the type you want to find using AssetDatabase.FindAssets.
Clear the list.
Loop all the found assets. Load the assets using AssetDatabase.GUIDToAssetPath and AssetDatabase.LoadAssetAtPath.
Add the found items to list.
I've used very little editor scripting, but I know this might update whenever you poke the inspector for this class... maybe there is way to detect event for created Assets, so that you'd only update your list then.