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

Question How to Use Sprite Assets Loaded From Addressables?

Discussion in 'UI Toolkit' started by auroch-freddie, Jun 12, 2023.

  1. auroch-freddie

    auroch-freddie

    Joined:
    Sep 7, 2021
    Posts:
    3
    Hello Unity Chums,

    For our game, we'll be displaying various glyphs in text with UI Toolkit. According to the documentation: https://docs.unity3d.com/2021.3/Documentation/Manual/UIE-sprite.html, this requires loading Sprite Assets from the Resources folder. However, we need to load these Sprite Assets using the Addressables system instead.

    When using TextMeshPro with UGUI, you can do this by adding the Sprite Asset to the MaterialReferenceManager after loading it from Addressables. Unfortunately it doesn't seem like this option is available in TextCore currently. There's also the Sprite Asset Fallback List in the Text Settings, although it looks like this isn't currently implemented.

    Are there any other aproaches I'm missing to using Sprites in UITK Labels after loading them from Addressables?

    Thanks,
    aurochFreddie

    Update:
    TextMeshPro 4.0.0-pre.2 includes updates to help with UITK integration, but still does not solve this issue.
     
    Last edited: Oct 3, 2023
  2. eggsamurai

    eggsamurai

    Joined:
    Oct 10, 2015
    Posts:
    99
  3. KruxieGod

    KruxieGod

    Joined:
    Feb 24, 2023
    Posts:
    1
    Hi, you can use built-in function in Addressables - LoadAssetAsync.
     
  4. auroch-freddie

    auroch-freddie

    Joined:
    Sep 7, 2021
    Posts:
    3
    Thanks for the reply!

    We can load the Sprite Assets just fine with LoadAssetAsync. The problem is then how to use those assets with TextCore in UITK at runtime.
     
  5. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    439
    Hi @auroch-freddie !

    TextCore expects the SpriteAsset to be in the Resources/ folder to be accessible at runtime.

    However, adding the SpriteAsset loaded from Addressable to the "Sprite Asset Fallback List" in the Panel Text Settings should work. Are you sure it was added to the Panel Text Settings from UI Toolkit (UI Document -> Panel Settings -> Panel Text Settings) ?
     
  6. auroch-freddie

    auroch-freddie

    Joined:
    Sep 7, 2021
    Posts:
    3
    Thanks Hugo!

    Using the Sprite Asset Fallback List works, but you aren't able to specify the Sprite Asset name, only the Sprite name. Makes it awkward if you have two Sprites with the same name in different Sprite Assets, but we can work around that by managing which Sprite Assets are loaded into the Fallback List.

    Thanks again!
     
    HugoBD-Unity likes this.