Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro TextMeshProUGUI - Camera Screenshot, Overlapping Text[Solved]

Discussion in 'UGUI & TextMesh Pro' started by IftMarco, Jun 28, 2019.

  1. IftMarco

    IftMarco

    Joined:
    Nov 12, 2018
    Posts:
    1
    Hi,

    found something... weird...
    Its only a Build Issue, on Editor it works so far.

    Unity 2018.2.16f
    Win10
    TextMeshPro 1.2.4
    Camera is Orthographic, only enabled for screenshot

    example pic:
    https://imgur.com/gPAZMSW

    Well in this example i just used two string.... but ofc it works with some iterations as well. They dont reset or are still cached somewhere. Camera is solid color white for clearing.
    Well, if i enable/disable screenshot camera after the text switch it looks good so far. Camera doesnt clear everything while enabled? Oh wait.. i can just activate the cam right before the screenshot happens, i do it already one step before. Well i found my "bugfix" while writing this thread... :D But still weird...
    Maybe somebody have this issue and it helps.

    Snipped/Pseudo Code:
    Code (CSharp):
    1.  
    2.  
    3. public void ToggleSwitch()
    4. {
    5.      if (isOn) {
    6.          aTextMeshProUGUI.SetText("WHY?");
    7.      } else {
    8.          aTextMeshProUGUI.SetText("TEST");
    9.      }
    10. }
    11.  
    Screenshot Code:
    Code (CSharp):
    1.      
    2.         RenderTexture rt = new RenderTexture(rtWidth, rtHeight, 24);
    3.         rt.useMipMap = false;
    4.         rt.filterMode = FilterMode.Point;
    5.  
    6.         cam.targetTexture = rt;
    7.         cam.Render();
    8.  
    9.         RenderTexture.active = rt;
    10.  
    11.         Texture2D tex = new Texture2D(rtWidth, rtHeight, TextureFormat.ARGB32, false);
    12.         tex.filterMode = FilterMode.Point;
    13.         tex.anisoLevel = 16;
    14.  
    15.         tex.ReadPixels(new Rect(0, 0, rtWidth, rtHeight), 0, 0);
    16.         tex.Apply();
    17.  
    18.         cam.targetTexture = null;
    19.         RenderTexture.active = null;
    20.         Destroy(rt);
    21.      
    22.         byte[] texBytes = tex.EncodeToPNG();
    23.         Destroy(tex);
    24.  
    25.         System.IO.File.WriteAllBytes(filepath, texBytes);
    26.