Search Unity

Question Sprite asset not rendering when dynamically changing text

Discussion in 'UGUI & TextMesh Pro' started by TheHighlander, Jan 24, 2023.

  1. TheHighlander

    TheHighlander

    Joined:
    Jan 11, 2023
    Posts:
    5
    Hi,

    I am trying to dynamically change the text field to change the sprite asset being rendered. My goal is to make a player health bar that changes as the text changes from:

    PLAYER: < sprite name = "healthbar_0" >

    to

    PLAYER: < sprite name = "healthbar_1" >

    I can get the text content to change correctly, but TextMeshPro renders the text literally and does not render the sprite asset. Am I doing something wrong? Or is this out of spec?

    Thanks,
    Wouter
     
  2. TheHighlander

    TheHighlander

    Joined:
    Jan 11, 2023
    Posts:
    5
    To clarify: the sprite names are checked to be correct. When I type these exact strings into the text box during runtime, the sprite assets are being rendered correctly.
    I feel like the TextMeshPro object needs a chance to parse the text field, which it isn't doing when I change the text at runtime.
     
  3. TheHighlander

    TheHighlander

    Joined:
    Jan 11, 2023
    Posts:
    5
    I have now solved my problem by using

    PLAYER: <sprite=0>

    NOTE that using < sprite = 0 > (including spaces) does not work.