Loading sliced Sprites with Addressables

As the title says, I’m wondering how to load sliced sprites with Addressables.

private void LoadSprites()
{
    AssetLabelReference label = new AssetLabelReference();
    label.labelString = "Whatever Label";
    var loading = Addressables.LoadAssetsAsync<Sprite>(label, LoadedSprite);
}

private void LoadedSprite(Sprite sp)
{
    print ("Loaded Sprite " + sp.name);
}

This code works fine for any count of single sprite textures, but when you slice a Texture2D it will only ever return the first sprite it finds.

Any idea how to do this?

1 Like

So I found out you can use AssetDatabase.LoadAllAssetsAtPath to load the remaining sprites like this:

private void LoadedSprite(Sprite sp)
{
     var data = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(sp.texture));

     for (int i = 0; i < data.Length; i++)
     {
          var sprite = data[i] as Sprite;

          //Do whatever you want here.
     }
}

Simple enough though I’m still left wondering why Addressables do not load sliced sprites.

EDIT: Nevermind I forgot that AssetDatabase is a part of UnityEditor namespace so it doesn’t work at runtime. Still stuck on this.