Search Unity

TextMesh Pro Copy component, paste its values or "as new"

Discussion in 'UGUI & TextMesh Pro' started by Silktrader, Jul 15, 2017.

  1. Silktrader

    Silktrader

    Joined:
    Aug 27, 2014
    Posts:
    8
    I'm having a rather annoying issue with the "copy component" operation on TMP UI elements. I am running the latest TMP from one of Stephan's posts and Unity 2017.1

    I generated a font with three variants (regular, bold and italic). I am using but one material for the moment and the default "Distance Field" shader.

    Every time I attempt to copy and paste a TMP UI component, which includes either bold or italic rich text, the new container I am copying it into inherits the first' position and attributes. It seems as if a reference to the original TMP UI remains the same. There's "TMP SubMesh" object that pops up and doesn't disappear, in the original TMP UI.

    Steps to reproduce:
    1. create a TMP UI component
    2. select a font which includes at least two variants (set in "Font Weights")
    3. copy the component
    4. paste it as new in a new gameobject

    My solution, so far, is to create ex novo each TMP UI which uses bold and italic. I'd rather copy paste things when I can't use prefabs.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The copy component is a general Unity implementation so it doesn't correctly handle the sub text object or internal references to it. Like you said, it ends up copying it where in this case it should create a new instance of that array.

    When I have time, I'll see if I can figure out an easy way to get around this.

    Copying the game object works fine so just this copy component has that issue.

    Update
    Looking at this, the behavior of copy component is interesting. When you past the new component, Awake, OnEnable and then Reset are called on the new object and thru those functions, the internal array that tracks the sub text objects is empty. However, as soon as OnValidate is called, that array has been de-serialized and now this array contains a reference to the source sub text object.

    I'll chat with the folks at Unity on Monday to get more insight on this.
     
    Last edited: Jul 16, 2017
  3. Silktrader

    Silktrader

    Joined:
    Aug 27, 2014
    Posts:
    8
    Thanks for the prompt answer.

    Yes, I confirm this much. One can get around by copying the entire game object. Sometimes it's not practical, because there can be quite a few components to remove, but it's a solution.

    The "SubMesh" object pops up when multiple fonts or materials are used. I've been using "bold" and "italic" styles to mark text, so far. But there are many cases when the "regular" style is simply not needed and I could select but the "Bold" font and material, mark it as "bold" (style) to increase its weight and avoid the "SubMesh" object. I am inclined to think that using the bold font and material, without referencing the regular font and material, would also yield better results performance wise. Is that so?
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The copy behavior happens with anything using sub text objects like alternative font face / weight, alternative font asset when using the <font> tag or even a sprite using the <sprite> tag.

    The reason for using font weights, is to get more accurate bold / italics instead of simulated one.

    In terms of performance, there is marginal impact from using multiple fonts, sprites and material per text object.
     
  5. Silktrader

    Silktrader

    Joined:
    Aug 27, 2014
    Posts:
    8
    This is a useless comment but, for what it's worth, the issue has been fixed. Unity 2017.1+ and TMP allow one to copy and paste TextMeshProUGUI components and their values even when they include sub text.

    Thanks.