LoadAssetWithSubAssets by name or matching indexes to names

Hi all,

I have an AssetBundle with a spritesheet containing 20 sprites. I have no problem loading the sprites using the following code:

	AssetBundle bundle = AssetBundle.LoadFromFile("Bundles/upgradeicons");
	if (bundle == null)
		Debug.Log("Failed to load bundle");
    Sprite[] itemSprites = bundle.LoadAssetWithSubAssets<Sprite>("UpgradeIcons");

But I would like to be able to access them by name, as I need to build objects at runtime from json, and would really like to use names instead of index, as a single delete in the sprite editor can messup all the indexes.

If I try to get all the names by:

string[] names = bundle.GetAllAssetNames();

I only get the name of the main asset.

So the questions are,

  • Are there any way to get subasset names from bundle?
  • Are there any way to load subasset by name from bundle? or match up indexes and names?

Would like to end up with dictionary with names and sprites.

Any input would be appriciated.

  • Henning

I can get the name of the sprite, but it’s just the name of the main asset and the index… Not usable :frowning:
So could reformulate the question: How do I force the bundle to save subassets names?

==> Subasset name for AssetSubasset0,AssetSubasset1…2.3…[For Particular Idetification]
string names = bundle.GetAllAssetNames();
if(names.Contains(" AssetSubasset"))
string allsubassetName = names;