Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Loading SpriteSheet Sprites With AssetReference

Discussion in 'Addressables' started by andiPossess, Aug 29, 2018.

  1. andiPossess

    andiPossess

    Joined:
    Dec 2, 2017
    Posts:
    1
    There doesn't seem to be a way of referencing anything but the default sprite on a sprite sheet (in this case, a texture imported with Sprite Mode Multiple) using this system.

    Loading via LoadAsset<Object>() results in a reference to the texture. Loading via LoadAsset<Sprite>() results in a direct reference to the first sprite, it seems. Either way, I can't get to the data about the sprites in the texture.

    Additionally, there's no way to add addresses for each individual sprite packed into a sheet, so I can't do it that way.

    Am I missing something here?
     
  2. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    294
    I don't know :)
    We haven't spent as much time as we'd like testing all the workflows, and sprite usage is one of them. I've added a ticket to our system to look into this, and hope to poke at it next week. I'll get back to you once I've been able to spend some time checking on this sprite case, as well as a few others.

    Thanks for testing out the system.
    Bill
     
  3. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    294
    Hi, we've looked into this, and I've got a slight update. The short version is that sprite-sheets don't play nicely with asset bundles today, and Addressables is a wrapper around asset bundles. So sprite sheets don't play nice with addressables. We are looking into ways we could mask the problems by doing some under-the-covers magic, but we haven't worked it all out yet.

    If you broke your sprite sheet up, and then made it into a sprite atlas you could have a slightly better time. In this scenario, you could make the atlas addressable, and load it through our system. From there you'd need to load the specific frame you were after using https://docs.unity3d.com/ScriptReference/U2D.SpriteAtlas.GetSprites.html

    This is something we could more easily create wrappers around so you could do the entire thing through addressables. We are looking into that as well.
     
    MNNoxMortem likes this.
  4. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    197
    So am I understanding this right, that there is no way to access the sub-sprites of a Multiple mode Sprite via code?

    Like I get not having looked at every use case under the sun, but how is "Iterate through sub-sprites by code" not right at the top of the list? Do you guys really expect people to set up their 2d animation clips using the Mechanim System? In production and at scale!? Come on guys... thats a complete mindless time sink that is totally unnecessary, and completely unsuited to rapid iteration in a large-scale production.

    I just assumed I would be able to write a simple script, that iterates through a multi-mode Sprite, at some FPS. It's really hard to believe this use case is not supported...I have a reference directly to the multi-sprite in the inspector, but somehow can not access it's children? Yeesh
     
    Last edited: Oct 3, 2018
    Alex_May and 5argon like this.
  5. Shlemon

    Shlemon

    Joined:
    May 17, 2013
    Posts:
    8
    I also think this feature is very important. Please add it soon!
     
  6. PaulBurslem

    PaulBurslem

    Unity Technologies

    Joined:
    Oct 7, 2016
    Posts:
    42
    With the latest addressables (.5.x), you can load sub assets (such as Sprites from a spritesheet) by specifying an IList<Sprite> or Sprite[] for your load type. Here is a quick example:

    Addressables.LoadAsset<IList<Sprite>>("MySpriteSheetAddress");

    This also works for getting animations from an fbx asset.
     
    MNNoxMortem and Shlemon like this.
  7. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    197
    Better late than never! Thanks Paul
     
  8. CapnCromulent

    CapnCromulent

    Joined:
    Sep 7, 2010
    Posts:
    42
    @PaulBurslem If I load a sprite sheet using IList, do I release each Sprite individually, or the entire IList?