Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Can't Sprite from Atlas using [] notation

Discussion in 'Addressables' started by wesmag, Jun 29, 2021.

  1. wesmag

    wesmag

    Joined:
    Mar 25, 2020
    Posts:
    34
    *Can't Load Sprite from Atlas using [] notation

    Hello! I am currently attempting to load a Sprite, from an included Atlas, into a SpriteRenderer and it appears the texture property of the loaded Sprite is null. I am including the atlas into an Addressables group simply by dragging the containing folder into the groups and building ("Use existing build" play mode). This does not work and there is no sprite visible.

    Code (CSharp):
    1. async void Start()
    2.     {
    3.         await TestLoad();
    4.     }
    5.  
    6.     async Task TestLoad()
    7.     {
    8.         var texture = await Addressables.LoadAssetAsync<Sprite>("objects/test.spriteatlas[box01_lid]").Task;
    9.         testSprite.sprite = texture;
    10.     }

    I am using the standard settings for all groups. Asset references appear to work fine using similar settings. The following is true in this case:
    1. I get a Sprite reference back
    2. Texture property is NULL
    3. Does not work in "Use Existing Build" mode.
    4. I have tried clearing caches (all of them)
    5. And I have tried rebuilding multiple times.
    6. Works fine in "Use Asset Database" mode.
    Aside from this setup, this is a blank project. So, can supply the project if needed.

    This appears to be related to this bug here

    I assume this bug still hasn't been fixed? Or, do I need to setup something else in order for the texture asset to build correctly into the bundle? @unity_bill ?

    Unity Version: 2020.3.12f1
    Addressables Version: 1.16.19

    Setup:

    Screenshot 2021-06-29 at 09.14.00.png
     
    Last edited: Jun 29, 2021
  2. wesmag

    wesmag

    Joined:
    Mar 25, 2020
    Posts:
    34
    Any thoughts on this? @unity_bill am I missing something or doing something wrong? Shall I submit a bug report with a sample project? Seems like a pretty simple question to answer.
     
  3. wesmag

    wesmag

    Joined:
    Mar 25, 2020
    Posts:
    34
    Turns out, standalone sprites are having the same issue. Loading via Key/Path with the entire directory included just doesn't seem to include Texture data for the included sprites. These sprites are not marked Addressable in the inspector, just added via their directory. The odd thing is, I use a similar method in another project when loading ScriptableObjects from bundle and this works fine, admittedly, I am loading via Label (as the key) and Type in that instance.

    Again, Simulate Groups mode works fine.

    If I mark the individual Sprite as Addressable in inspector it gets added to the Default group. If I load using its path in that group, the sprite load correctly in all modes.

    I am probably missing an important detail here, but it also just doesn't seem consistent.
     
  4. wesmag

    wesmag

    Joined:
    Mar 25, 2020
    Posts:
    34
    Turns out, after all that nonsense the main issue was: Edit -> Project Settings -> Editor -> Sprite Packer -> Mode -> Change to Sprite Atlas V1 - Always Enabled

    Prior to this it was Sprite Atlas V1 -> Enabled for Builds

    I am not currently sure what the link is (but I simply assume that the packer setting is regarded even with manual builds of Addressables) regarding loading single sprites from Addressables here. But if I change it back "Use Existing Build" mode no longer works.
     
    Last edited: Jul 3, 2021