Search Unity

Question How to load sprites?

Discussion in 'Addressables' started by Nyankoooo, Nov 2, 2020.

  1. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    Hello everyone,

    I have multiple large .png files I want to make as Addressables, but to make the issue more simple, lets assume I only have one large .png file in my project.

    I marked that .png file as an Addressable, uploaded it to my remote location, but when I'm trying to load it, I can't load it as a Sprite but only as a Texture2D.

    Is there a way to directly build the Addressable as a Sprite, or is the only option to load the Texture2D and then create a Sprite out of it?
     
  2. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
    What version of Addressables are you using? I've run into a handful of issues with sprites on older versions, including one that was similar to yours, but they're all resolved on the latest version of the Addressables package.
     
  3. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @dlegare-synapse I have version 1.16.7 installed, but I'm getting this error:
    Code (CSharp):
    1. Unable to load asset of type UnityEngine.Sprite from location Assets/MyLocalPathToThePNG/imageName.png
    when calling this code
    Code (CSharp):
    1. Addressables.LoadAssetAsync<Sprite>(location)
    where "location" is the path to the Addressable.
     
  4. dlegare-synapse

    dlegare-synapse

    Joined:
    Jan 17, 2018
    Posts:
    54
    All of the sprite-related issues I know of are fixed in Addressables 1.16, so what you're running into is probably different than the issue I was thinking of. The only other thing I can suggest double-checking is that you have the texture type set to "Sprite" for your sprite asset:

    upload_2020-11-2_15-16-23.png

    If you already have that setup, then I'm not sure what would be causing the issue. This kind of sounds like a bug to me, though, since you seem to be doing the right thing. Maybe file a bug report in that case?
     
  5. niuage

    niuage

    Joined:
    Nov 17, 2019
    Posts:
    123
    I had the same issue, and I found the solution:

    upload_2023-2-25_18-7-36.png

    It's not enough to set the Texture Type to Sprite, you also have to set the Sprite Mode. Without it, it doesn't work.

    Once you've done that, the sprites in the addressable group should look like this:

    upload_2023-2-25_18-9-9.png
     
  6. Jiang

    Jiang

    Joined:
    Jul 16, 2012
    Posts:
    1