Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted How to load sprites?

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

  1. MardukCorp

    MardukCorp

    Joined:
    May 21, 2016
    Posts:
    90
    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. MardukCorp

    MardukCorp

    Joined:
    May 21, 2016
    Posts:
    90
    @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?
     
unityunity