Search Unity

TextMesh Pro Textmeshpro letters overlap

Discussion in 'UGUI & TextMesh Pro' started by HardK, Mar 30, 2020.

  1. HardK

    HardK

    Joined:
    Nov 5, 2016
    Posts:
    7
    Hey there,

    I'm trying to create the text displayed on top, playing with both the outline and underlay options on the textmeshpro material.

    textmeshpro_overlap.png

    But this is as far as i could get. I think i would probably need to change the render order of the different materials but can't find the handles for it. Does anyone know how it would be possible to achieve this effect?

    Many thanks
     
  2. HardK

    HardK

    Joined:
    Nov 5, 2016
    Posts:
    7
    Bump.

    Does anyone know how i could do this? The way i see, i would need to render all the underlays first, then outlines and then face letters in the end. Not sure if this is possible out of the box or i'm missing something here.
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Having the ability to combine visual styles such as Outline, Shadow, etc. per word / word segment is functionality that I would like to have available in the future. No firm ETA but definitely something possible.

    In the mean time, you could achieve something similar by using two text objects where the background object is using a material with dilation, outline and shadow (without transparency to create the two level of outline) then the play white text is in front.
     
  4. HardK

    HardK

    Joined:
    Nov 5, 2016
    Posts:
    7
    Hey there Stephan,

    I followed your sugestion and ended with the intended result, although this is gonna be really messy to maintain :p , because the texts will always have to be updated in all the objects and plus the rendering of all the additional components and materials.

    Anyway, thank you :) I didn't thought of separating it in actually 3 different objects. Cheers

    image (2).png image (3).png
     
  5. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Maybe TextMesh Pro has some sort of "textChanged" callback you could subscribe to? Then it should be possible to only update one TMP object and the other TMP objects would listen to text changes and update themselves accordingly. Not sure if already possible, but that could be one approach to handle it with a little less headache.
     
  6. HardK

    HardK

    Joined:
    Nov 5, 2016
    Posts:
    7
    Yeah i ended up creating a prefab with a script that does just that. Way easier to replicate since i have many of these texts and they change dynamically :)

    spriteTextUI.gif

    I'm leaving the script here, might eventually help someone in the future. Just place the script in an object with the TMP components as children and it'll change the text of all of them.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using TMPro;
    4. using UnityEngine;
    5.  
    6. [ExecuteInEditMode]
    7. public class SpriteTextUI : MonoBehaviour
    8. {
    9.     public string text;
    10.  
    11.     private string _lastFrameText;
    12.     private List<TextMeshProUGUI> _tmpTexts;
    13.  
    14.     private void OnEnable()
    15.     {
    16.         _tmpTexts = new List<TextMeshProUGUI>(GetComponentsInChildren<TextMeshProUGUI>());
    17.     }
    18.  
    19.     void Update()
    20.     {
    21.         if (HasTextChanged())
    22.         {
    23.             UpdateSpriteTexts();
    24.         }
    25.     }
    26.  
    27.     bool HasTextChanged()
    28.     {
    29.         bool textChanged = false;
    30.  
    31.         if (text != _lastFrameText)
    32.         {
    33.             textChanged = true;
    34.         }
    35.  
    36.         _lastFrameText = text;
    37.  
    38.         return textChanged;
    39.     }
    40.  
    41.     void UpdateSpriteTexts()
    42.     {
    43.         foreach (var tmpText in _tmpTexts)
    44.         {
    45.             tmpText.text = text;
    46.         }
    47.     }
    48. }
    49.  
    Cheers
     
    PyrokidSosa and Stephan_B like this.