Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

TextMesh Pro TMPro Recognizing Sprite Asset But Rendering as Invisible and Throwing Error

Discussion in 'UGUI & TextMesh Pro' started by DylanIlvento, Aug 15, 2022.

  1. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Hello all!

    I was reimplementing an old sprite asset I created a little while ago in TextMesh Pro, but I can't get it to work, despite having success with it in the past (though that was with world space TMP, and I've since switched to TMP UI). When I add the sprite tag, such as
    <sprite index=0>
    the tag disappears, presumably because it's rendering it, but no sprite shows up. The console starts to throw a NullReferenceException as soon as I finish entering the last character of the tag:

    NullReferenceException: Object reference not set to an instance of an object
    TMPro.TMP_Text.CalculatePreferredValues

    Would really appreciate some help on this since I don't really know how to troubleshoot this further on my own. I've attached a screenshot of the error in editor. I'm currently on Unity 2021.3.6f1 on an Apple Silicon Macbook Pro.
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Can you post an screenshot of the sprite asset inspector where I can see both the characters and glyphs?
     
  3. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Hi @Stephan_B, here are the screenshots you asked for! There are multiple pages of glyphs, so I didn't screen grab every single one. Let me know if there's any additional information you need! Thanks!
    upload_2022-8-17_14-20-58.png upload_2022-8-17_14-22-11.png upload_2022-8-17_14-23-2.png
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    What happens if you assign the above font asset to the text object as a local sprite asset in the Extra Setting panel of the text component?

    Once assigned as a local sprite asset, and use the following text "A <sprite=1> B", does the sprite display?
     
  5. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Hey @Stephan_B!

    I went ahead and tried your suggestion, but it still renders as an empty space. I've included screenshots of the text input assigned to "A <sprite=1> B" as well as the sprite asset assigned to the local sprite asset variable. I'm curious if the material assigned to the sprite asset might have something to do with it? Right now it's using the
    TextMeshPro/Sprite
    material.

    upload_2022-8-21_9-51-8.png
    upload_2022-8-21_9-51-36.png
     
  6. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Hey @Stephan_B! So I recreated the sprite asset from scratch (and also reimported the TMP Essential Resources), and that seems to have fixed the issue? I also had to restart my Unity project after doing this, cause it was throwing a bunch of errors before and still not rendering the sprite asset. No idea if there was a meta file issue that got fixed or something, but yeah, it looks like it's working now. I'll let you know if any other issues crop up from this!
     
  7. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Looks like I may have spoke too soon. While this new sprite asset does seem to be working, sometimes it continues to throw the
    NullReferenceException
    (s) mentioned at the top of this thread and then doesn't update changes made to the asset, such as global offset and whatnot. It continues to work, but seems extremely unstable. I don't know if this is a deeper issue that can only be fixed with a future update or what, but I'll continue to keep an eye on it.
     
  8. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    So after a day of it working semi-reliably, I realized that for some reason the sprite asset's meta file won't update, so any changes I make to it won't be reflected in my source control. Again, I don't know if this is some lingering issue with the sprite asset itself or possibly the
    Resources/Sprite Assets
    directory. In either event, I seem to be back at square one, since the sprite asset is back to its old ways of not rendering. I can roll back to a point where it was working earlier today, but that doesn't address the issue of the meta file refusing to update, so the sprite asset renders pretty small inline. Would love any help with this!
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Can you export this sprite asset and provide it to me in a PM? This will enable me to look at it to see if I can figure out what is going on with it.
     
  10. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Can do! I'll send this your way sometime today. :)
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Thank you for providing me with the Sprite Asset and related files via PM.

    I had a chance to look at it tonight and noticed that no Sprite Atlas (Texture) was assigned to it. As such, I re-assigned the .png file that you provided to it as seen below.

    upload_2022-8-24_0-14-27.png

    I also double checked that the default material (child of the sprite asset) was also referencing this .png texture.

    I then created a text object where I assigned this sprite asset as a Local sprite asset in the Extra Settings of the text object as seen below.

    upload_2022-8-24_0-14-12.png

    I then set the text to "X<sprite=9>X> where as seen below the sprite displayed as expected.

    upload_2022-8-24_0-15-17.png

    I then moves this sprite asset into a Resources folder at the location specific in the TMP Settings which is "Resources/Sprite Assets/..." and then referenced the sprite asset by name in the text along as seen below where this also worked as expected.

    upload_2022-8-24_0-17-22.png

    So other than the missing reference to the texture, the sprite asset seems to be fine. Is this sprite asset missing the reference to the texture on your end?
     

    Attached Files:

  12. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Hey Stephan!

    No, the sprite asset wasn't missing the reference to the texture for me. That missing reference probably happened when I sent you the files. If you try to change the point size or the scale for the sprite asset under the face info heading, will that info be reflected in the sprite asset's meta file? Cause that is still the issue for me.

    Thanks!
     
  13. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    In order for the Face Info setting to work, you have to set both the point size and scale and should be setting up the Ascent and Descent line value. To set those up and visualize these metrics, I would suggest adding a TMP_TextInfoDebugTool.cs script to a text object using this sprite. The TMP_TextInfoDebugTool.cs script is in the TMP Examples & Extras.

    Below is an image with the updated FaceInfo metrics which I set using the TMP_TextInfoDebugTool.

    upload_2022-8-24_12-7-56.png

    upload_2022-8-24_12-8-9.png

    I did save the scene and closed Unity and the modified sprite asset settings were preserved. These settings are serialized with the sprite asset and not its .meta file.
     
  14. DylanIlvento

    DylanIlvento

    Joined:
    Apr 23, 2020
    Posts:
    9
    Ok, it looks like the sprite asset finally updated! It wasn't showing up in the diff in my git client before, but now it seems to be. Thanks!
     
  15. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Glad it is working onw. Let me know if this behavior resurfaces.