Search Unity

New TextMesh Pro Sprite Asset Importer, Data Source

Discussion in 'UGUI & TextMesh Pro' started by nyonge, Oct 19, 2018.

  1. nyonge

    nyonge

    Joined:
    Jul 11, 2013
    Posts:
    49
    Edit Mar 2020: apparently this info is out of date, I haven’t tried it myself but if you’re using a recent version of TMP as of March 2020 refer to @BoaNeo’s post below (thx!)


    I just spent several hours figuring out how to create/import Sprite Assets using the new TMPro sprite asset creator. I finally got it. Consider this post a resource for anyone else in a similar situation - I'm posting this because the documentation is hugely lacking for the new Unity TextMesh Pro update.

    There's a new mandatory field in the importer called "Sprite Data Source" that requires a text file asset. This needs a JSON file, not txt, not a script. There's also an "Import Format" dropdown that (for me at least) has only two options, "none" and "Texture Packer". None doesn't work at all, Texture Packer is designed for TexturePacker by CodeAndWeb (which is actually an awesome piece of software).

    To create a Sprite Data Source file, you have to set up your sprite atlas using Texture Packer, and use the JSON Array data format. This is important – other JSON formats didn't work, and neither the default Unity format nor Unity's JSON format worked either.

    That outputs a JSON file that works with Sprite Data Source. The Texture Atlas should be good too, but I preferred using a texture atlas output from TexturePacker using its default Unity data format. (Note that when outputting the JSON file, you might have to play with the Pivot Point setting too. For me, "Top Left" worked.)

    (Apologies for the wordy post, but there's NO documentation for how this feature changed. When searching for "Sprite Data Source", for Unity TMP TMPro TextMeshPro TextMesh Pro or anything, only this changelog appears that says it changed and won't work, but doesn't have much more info. Hopefully this can help somebody else!)

    Edit Oct 2019: It seems changing the pivot point in TexturePacker is a Pro feature. TP is about $50 and super worth it, if you can swing it! I use it on every project and will happily recommend it. But if that's not feasible, it'd be time consuming but you could probably manually edit the exported JSON file. Thanks for pointing that out @llMarty
     
    Last edited: Mar 28, 2020
    CC_YN, HugoBD-Unity, ranch000 and 7 others like this.
  2. nieyoub23

    nieyoub23

    Joined:
    May 8, 2016
    Posts:
    27
    Thanks for posting, helped me a lot.
     
  3. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Thank you!

    This was driving me crazy. I had no idea I needed to use an external texture packer.
     
  4. llMarty

    llMarty

    Joined:
    Dec 14, 2014
    Posts:
    33
    Yes, I can confirm this works like charm, unless you do not pay for Texture Packer, the "Top Left" pivot sprite setting is a PRO feature.
     
    nyonge likes this.
  5. BoaNeo

    BoaNeo

    Joined:
    Feb 21, 2013
    Posts:
    56
    This is a bit outdated and sent me down a wrong path (also, it did not work for me, for whatever reason). What worked for me in Unity2019 is way easier: Just select your UI texture, then go to Assets->Create->TextMeshPRO->Sprite Asset and Unity will create a TMP sprite asset with all of your sprites in it. No need for external tools or fiddling with Json files.
     
    itsharshdeep and nyonge like this.
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Just as a reminder and as @BoaNeo just stated, you can import the texture that contains your sprites in Unity, then select this texture and set it to Sprite 2D with Sprite Mode Multiple and then use the Sprite Editor button to define / slice the sprites. Once the slicing is done, then use the context menu Assets->Create->TextMeshPRO->Sprite Asset with this texture selected.

    P.S. Once the sprites have been defined and the sprite asset created, you can switch the texture back to Default. Note that doing so will lose the slicing information for this texture in the Unity Sprite Editor (last time I checked anyway) in case you need to edit these sprites.

    Why would you switch the texture back to default? This is an actual performance overhead when loading these Sprite 2D textures when they contain lots of sprites. Especially on mobile devices. So once the sprite asset has been created, it is perfectly fine to switch it back to default to remove this overhead. Maybe keeping the texture in Sprite 2D mode while working on the project is fine but when creating your final build for shipping, it might be a good idea / last step to switch those back to default.
     
    CC_YN, restush96 and hugogfadams like this.
  7. amateurd

    amateurd

    Joined:
    Nov 1, 2016
    Posts:
    97
    Sorry Stephan, but this doesn't work (at least on my version of TMPro). The only import option is TexturePacker. If you select "None" then you can't import the sprites at all.

    The downside of TMPro not supporting Unity's standard sprites (Sprite mode multiple) is that if your project needs to use them outside of TMPro then you need to duplicate the sprite sheet, which doubles the storage (and memory) for the sprites.

    There doesn't seem to be a way to create a single sprite sheet in TexturePacker which can be used by both Unity and TextMeshPro.

    The only workaround I have found is to use a standard sprite sheet which Unity can use, and then write the JSON array by hand (which is tiresome to say the least!)
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The above option is specific to importing sprites packed with TexturePacker in JSON (Array) format.

    Creating sprite assets from a texture (set to Sprite mode Multiple) where the sprites were defined in the Unity Sprite Editor is supported. To create this sprite asset selected the texture after you have defined the sprites and use the Context Menu - Create - TextMeshPro - Sprite Asset. See the following video (which is old but still relevant).