How can I get a sub asset?
I have an ItemDatabase.asset and when I add items there I also create copies as subjects of the Item Database.asset.
To do this I use the following method.
var itemAsset = CreateInstance<Item>();
itemAsset.name = addItem.name;
AssetDatabase.AddObjectToAsset(itemAsset, itemDatabase);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(itemAsset));
itemDatabase.items.Add(itemAsset);
How can I remove the desired sub asset?
Answer by templewulf · Dec 31, 2018 at 02:08 AM
Unfortunately, the only way is to iterate through all of the objects in the asset in a script and use Destroy() on the right one.
I have a custom editor that searches all of the objects in an asset, finds any with a matching name and destroys them all before creating a new one. Otherwise, you end up with lots of matching objects within an asset orphaned off because they can't be deleted.
You can also try to find a third-party tool that can manipulate assets for you. I've heard good things about this one: https://forum.unity.com/threads/a-simple-sub-asset-editor.543475/
Your answer
Follow this Question
Related Questions
ScriptableObject not saving to Asset properly 0 Answers
AssetDatabase.LoadAssetAtPath Not finding assets 0 Answers
Load Assets into Unity without Asset Bundle at Runtime 0 Answers
ScriptableObjects inside another ScriptableObject not saving changes in Custom Editor Window 0 Answers
Changes to asset data persist - unable to discard changes 1 Answer