Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Pixel-Perfect Dynamic Text - Support Thread

Discussion in 'Assets and Asset Store' started by tonic, Feb 16, 2014.

  1. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Hi Tonic. I guess this is not possible, but will ask anyway :) Is there a simple way to put Dynamic Text on a cylinder or a sphere?
     
  2. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    No, no simple way to do that. I guess it would be possible though by making a custom vertex shader and tweak the text that way to lie on top of surfaces like that. There is another asset called "Text Box 2" from Catlike Coding, and by screenshots it looks like it supports that kind of transformations, perhaps you'd like to try it.
     
  3. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Thank you so much! I really appreciate your suggestions.
     
  4. aparraga

    aparraga

    Joined:
    Aug 13, 2014
    Posts:
    20
    Hi, Tonic
    Do you have any ETA to fix the bug?
    We need to know in order to align it to our internal roadmap. Thank you!
     
  5. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    I have a separate test version built only for Unity 5 which you could test out. Please send me email (contact at strobotnik.com).
     
  6. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Hi Tonic,

    I have a follow-up question. Is it possible to change the text color during run-time? The DynamicText.color doesn't work, probably because of the custom material. I'm guessing that I would need to get to the material color and dynamically change it?

    Thanks!
     
  7. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Dynamic Text puts the given color to vertex colors of the mesh, so make sure your custom material uses the color from there. You can download source of Unity's built-in materials and look at the Font shader for reference.
     
  8. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    This is the shader that I copied from the page that you recommended:

    Shader "GUI/3D Text Shader" {
    Properties {
    _MainTex ("Font Texture", 2D) = "white" {}
    _Color ("Text Color", Color) = (1,1,1,1)
    }
    SubShader {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    Lighting Off Cull Off ZWrite Off Fog { Mode Off }
    Blend SrcAlpha OneMinusSrcAlpha
    Pass {
    Color [_Color]
    SetTexture [_MainTex] {
    combine primary, texture * primary
    }
    }
    }
    }


    Sorry, I know next to nothing about writing shaders, so what would be my next step? If it's too involved, I'll just skip this for now.
     
  9. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Maybe try this one. It's almost identical to the Font.shader from Unity 4.6.5, only "ZTest Always" has been removed and the shader name has been changed to "GUI/3D Text Shader 2".

    Code (CSharp):
    1. Shader "GUI/3D Text Shader 2" {
    2.     Properties {
    3.         _MainTex ("Font Texture", 2D) = "white" {}
    4.         _Color ("Text Color", Color) = (1,1,1,1)
    5.     }
    6.  
    7.     SubShader {
    8.  
    9.         Tags {
    10.             "Queue"="Transparent"
    11.             "IgnoreProjector"="True"
    12.             "RenderType"="Transparent"
    13.             "PreviewType"="Plane"
    14.         }
    15.         Lighting Off Cull Off ZWrite Off Fog { Mode Off }
    16.         Blend SrcAlpha OneMinusSrcAlpha
    17.  
    18.         Pass {  
    19.             CGPROGRAM
    20.             #pragma vertex vert
    21.             #pragma fragment frag
    22.  
    23.             #include "UnityCG.cginc"
    24.  
    25.             struct appdata_t {
    26.                 float4 vertex : POSITION;
    27.                 fixed4 color : COLOR;
    28.                 float2 texcoord : TEXCOORD0;
    29.             };
    30.  
    31.             struct v2f {
    32.                 float4 vertex : SV_POSITION;
    33.                 fixed4 color : COLOR;
    34.                 float2 texcoord : TEXCOORD0;
    35.             };
    36.  
    37.             sampler2D _MainTex;
    38.             uniform float4 _MainTex_ST;
    39.             uniform fixed4 _Color;
    40.            
    41.             v2f vert (appdata_t v)
    42.             {
    43.                 v2f o;
    44.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    45.                 o.color = v.color * _Color;
    46.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    47.                 return o;
    48.             }
    49.  
    50.             fixed4 frag (v2f i) : SV_Target
    51.             {
    52.                 fixed4 col = i.color;
    53.                 col.a *= tex2D(_MainTex, i.texcoord).a;
    54.                 return col;
    55.             }
    56.             ENDCG
    57.         }
    58.     }
    59. }
    60.  
     
  10. aparraga

    aparraga

    Joined:
    Aug 13, 2014
    Posts:
    20
    Another issue is that the text does not honor the mask it is inside of (see image), so how can we do that?
    Thank you in advance!
    [​IMG]
     
  11. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Hi! Unfortunately this goes beyond what is currently supported by the Dynamic Text asset - there's no support for any "tight" or "deep" integration to UI libraries with fine details like that.

    For that case you're having, I recommend you use the text drawing provided by the UI library you're using, instead of Dynamic Text.

    Alternatively perhaps you can create a custom script which fades out the text a bit before it hits the edge of that rectangle, so that it is completely transparent before it overlaps with the edge.
     
  12. aparraga

    aparraga

    Joined:
    Aug 13, 2014
    Posts:
    20
    awesome, thank you tonic
     
  13. codehesk

    codehesk

    Joined:
    Jun 16, 2014
    Posts:
    7
    According to your code in 3d shader as above, how do you change the shader on the text mesh? I am trying to make it to cull back on its display on the text. I am trying to make it enabled for with the 3d shader.

    http://wiki.unity3d.com/index.php?title=3DText
    Maybe if you can make a check box to enable this feature. Because I need it.

     
  14. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
  15. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Hi Tonic. Just wanted to thank you again. This shader works with DynamicText.color. Very cool!
     
  16. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Hi Tonic. Do you have any advice on how to make text move smoother?

    My use case: 2D trucks driving horizontally. Every truck has a word or two written on it. When the trucks move, the text appears to jitter a little, so this makes the game look unnatural. I'm not saying this is a bug, but I'm curious if you as an expert have any suggestions on how to fix that.

    Thanks!
     
  17. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Hi @username132323232, the little jitter you're seeing comes from the pixel snapping feature of the text which keeps it "crispier". For a freely moving text I recommend you just toggle it off, especially when the text is bound to some other geometry like that.
     
  18. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Thanks again!

    Just a quick follow-up question. Do you have a suggestion on how to make a moving sprite behave the same (no pixel jitter)? I'm guessing that anti-aliasing is the way to go, but unfortunately there is a bug in Unity that doesn't allow my builds for iOS to use texture anti-aliasing.

    Sorry, this question is not about the Dynamic Text asset per se, but if you could point me in the right direction, that would be great :)
     
  19. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    @username132323232, if you're getting "pixel jitter" with a sprite, I'm assuming there's some similar pixel perfect adjustment flag enabled in the 2D system you're using... or alternatively using texture Point sampling can cause it - if that's so, try changing to Bilinear sampling.
     
  20. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Thanks! I'll check those out. I think you should write a book. If you do, I'll be the first to buy it.
     
  21. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Heh, thanks for the kind words. That'd be fun, but I don't think I have enough time for such a project. :)
     
  22. adrianfielding

    adrianfielding

    Joined:
    Jun 11, 2013
    Posts:
    6
    I am having an issue with the plugin and using the IL2CPP scripting backend in Unity. The text using the Dynamic Text plugin no longer renders although text generated using Textmesh is visible. This issue is occurring in Unity 4.6.7f1.

    Everything renders as expected which using Mono scripting backend, the error only occurs when switched to IL2CPP.

    Any advice on how to resolve this issue would be greatly appreciated
     
    Last edited: Jul 27, 2015
  23. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Hi @adrianfielding, which Unity version are you using? I think I have fixed that bug but I'm not entirely sure if that fix is yet in the currently available version.
    In case you're still getting the problem with latest version from asset store, please email to contact (at) strobotnik.com -- Especially if you're using Unity 5. A new version will be released soonish with better Unity5 specific implementation (along with a fresh build for Unity 4). But if you're in a hurry, you can get a pre-release build.
     
  24. adrianfielding

    adrianfielding

    Joined:
    Jun 11, 2013
    Posts:
    6
    Updated to the current version, changed code to use SetText() instead of DynamicText.text. Works perfectly! Thanks for your prompt response.
     
  25. vorce67

    vorce67

    Joined:
    Sep 11, 2012
    Posts:
    3
    Have you noticed a small lag time on iOS when enabling a dynamic text object for it to actually be drawn? I am noticing this on Unity 5.1.2f1 but never experienced it on Unity 4. This issue also does not appear to show up on Android. I notice the lag when I disable some Dynamic text objects and show a full screen GUI on screen. I then disable the full screen GUI and enable the Dynamic text objects but they take a small delay before appearing. The rest of the GUI enables before the Dynamic text is shown. I may try enabling the Dynamic text objects a few frames earlier as a potential workaround.
     
  26. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Hi @vorce67 - sorry for slow reply, for some reason I didn't get email notification of a new post. I have a better version w/Unity 5 support somewhat ready for release, which may very well fix the issue you're seeing. If you want to test the new version before I release it in the asset store, please send email to contact (at) strobotnik.com.
     
  27. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    New version of Dynamic Text is now released! Version 1.1.0 has Unity 5 support, find it in the Asset Store.
     
  28. ptblk

    ptblk

    Joined:
    Mar 27, 2015
    Posts:
    57
  29. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    @ptblk, framerate hickups are possible to happen when rendering bulk of text with new characters, especially with big size and many new characters which weren't used previously. This "problem" is natural part of how Unity's Font system works or any similar system which dynamically renders new glyphs to a font atlas.

    In case of a simple app with a known set of glyphs needed, in my asset one can enter a string of all required chars to field called "Metrics Ref Chars" in which case the Pixel-Perfect Dynamic Text will pre-render those on initialization (or when the actual needed pixel size for text changes), which can help to reduce potential hickups.
     
  30. ptblk

    ptblk

    Joined:
    Mar 27, 2015
    Posts:
    57
    Great thanks for the feedback
     
  31. Floutre

    Floutre

    Joined:
    Jan 22, 2016
    Posts:
    3
    Hello

    Digging this subject out of his 6 month old grave as I am facing an issue I would dare to call a bug.

    I have a situation where the HUD in my game hides/shows some texts according to some criteria. I achieve that by activating/deactivating the game object to which the DynamicText is attached.

    myDynamicText.gameObject.SetActive(false);

    The thing is, when I reactivate the object, the text displayed has been reset to what has been entered in the editor. Any call to SetText() through script before that is working fine, but as soon as I deactivate and then reactivate the object, the text is reset.

    I assume it is reset to the serializedText content. It seems it is not happening in the editor. It is in a standalone build (targetting PS4 for that matter, not sure it changes anything here).

    Any thoughts on this?

    Thanks
     
  32. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Hi @Floutre, that indeed sounds like a nasty bug! I don't have any access to PS4 dev HW. But here's some thoughts and requests / follow-up questions.

    - First, please verify you're using latest version (1.1.0).
    - Have you tested on in a normal desktop windows standalone build? I'd expect that to manifest also that way.
    - Is the object created from a prefab or just directly in the editor?
    - Are you perhaps using a DynamicText object which was originally created with older DT version (or Unity version), and then later upgrading the DT or Unity version, while using the "same" object? If so, please try if deleting the DT object from scene and re-create a new fresh DT object, and see if the new object still works wrong. (There's some internal version upgrade code which might might as well have a bug as well..)
    - What Unity version are you using?

    In addition, it would actually be most helpful if I could get a small test scene where the bug is reproduced (with no other dependencies present). This would help debugging, and also to make sure the bug isn't about weird linked behavior with other code/assets. If you could make this, please send by email to contact (at) strobotnik.com.
     
  33. FrederikSiepe

    FrederikSiepe

    Joined:
    Jan 31, 2017
    Posts:
    1
    Hi @tonic , I have a question about your asset before I buy. It says 'camera facing text meshes'. Does that mean that for a 3D camera the text will always face towards the camera? Or can it be rotated freely?
    Thanks, Frederik
     
  34. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Oops, wording of that could be a little bit better.

    The intention is to say that the text faces the camera (optionally). For the text to be properly pixel-perfect, it needs to face the camera. The camera is not forced to be orthogonal or axis-aligned.

    Two additional things: (1) If you're looking into integrating with the newer unity UI, then you should just use its built-in pixel perfect text features. That UI system wasn't yet available when this asset was released. (2) It's recommended you do a test of the asset using the "Lorem ipsum" demo version available from this page: http://strobotnik.com/unity/dynamictext/
     
  35. Klangerfinder

    Klangerfinder

    Joined:
    Feb 9, 2017
    Posts:
    1
    Hi @tonic, we just bought the asset and wondered if it is possible to hide 3D text behind other objects?
    Any help would be appreciated :) Thanks
     
  36. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
  37. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Hi @tonic, Is it possible to have text follow a path, such as an arc or a circle?
     
  38. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    No, that's not a supported feature. This asset is just about doing crispy regular text, there are other text assets which should be better for any special effects type of stuff.
     
  39. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    Sounds good. Thanks! Any suggestions about text assets that could do that?
     
  40. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Sorry, can't recommend one as I haven't had the need to do such thing in Unity.
     
  41. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    254
    No problem, thanks anyway :)
     
  42. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Version 1.2.0 released, containing a fix for using combination of DirectX9 with Unity version 5.5 or newer.
     
  43. Multiplayer

    Multiplayer

    Joined:
    Dec 29, 2012
    Posts:
    14
    Hi @tonic

    I just ran into the exact same problem as @Floutre , meaning that all texts reset to their original value when you deactivate / reactivate them. This, of course, clashes with translations and similar text changes while the game is running.

    This happened after I upgraded from Unity 5.4 to 5.6, and all of my old Dynamic Texts became very blurry. The same is true if I upgrade to 5.5 only. So I upgraded DynamicText to the current version 1.20. This fixed the blurriness, but causes the text values to reset upon reactivation. In my case, this happens for Windows Builds, but not in the editor (as was the case for @Floutre with PS4 and the Editor)

    As you suspected, creating new DynamicText objects fixes the problem. Only old leftovers are affected. However, re-doing all of the text objects in my game is basically asking for bugs, so I am not a huge fan of the idea. Is there any other fix for this problem by now? Alternatively, is there an older version of DynamicText that fixes the blurriness, but won't show this behavior? I don't need any fancy new functionally, just the usual crispness.
     
  44. Multiplayer

    Multiplayer

    Joined:
    Dec 29, 2012
    Posts:
    14
    Update:

    @Floutre seems to be right that the text is reset to the content of serializedText. Setting this value manually, in addition to calling setText(), seems to solve the problem. However, always calling both of these together is not a great solution code-wise. I also do not know what other ramifications this would have, now or in the future. I'd much rather have this work without such tricks.
     
  45. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    @Multiplayer, thanks for reporting this.

    The blurriness is about Unity adopting to easier way of DX9 pixel sampling in 5.5+, so I had to disable some of my own code to do similar thing when a newer Unity version is being used.

    I find it hard to reproduce the text activation/resetting bug. Just tried by making a scene with DT and script which changes its contents as well as deactivates&activates it. And tried that also to a few older saves of scenes with DT objects. I'm sure the issue is connected to some internal code which "upgrades" objects which have been made with older versions. But I find it hard to reproduce, so I guess there is some corner case with certain old version being the basis or so.

    Could you create a simple scene with a text showing the bug, and send that to me by email? (contact at strobotnik dotcom) You may need to make it as a copy of existing scene and delete unneeded stuff, if the bug does never shows up with re-created text instances.

    Edit: @Multiplayer, Are you perhaps setting the text while it is disabled? That case seem to work erroneously. Internally that's because of some difficulties with editor's undo/redo system and how the serialization works with that, but I guess I should be able to fix that now that I realized at least that. It might become a fix for your issue as well, but I'd still appreciate a test scene if you can do it.
     
    Last edited: May 2, 2017
  46. Multiplayer

    Multiplayer

    Joined:
    Dec 29, 2012
    Posts:
    14
    I just sent you a minimal example showing the problem. While the project where I actually use DynamicText does translate (and therefore set) labels while they are inactive, this is not the case for this minimal example. I hope the example I sent you behaves the same on your system^^
     
  47. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    We figured out the above-mentioned issue together with @Multiplayer, so a fix for that will be included in the next release.
     
  48. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Version 1.2.1 is now released, fixing the issues related to text reverting when disabling/enabling objects. Also verified Unity 2017.1.0b compatibility.
     
  49. DanielSchmidt

    DanielSchmidt

    Joined:
    Dec 2, 2015
    Posts:
    4
    Hello, a couple of months ago we started getting random appearing errors from DynamicText.
    So I just updated to try and remove them, but sadly that didn't change anything:

    MissingReferenceException: The object of type 'DynamicText' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    DynamicText.GenerateMesh ()
    DynamicText.a (UnityEngine.Font A_0)
    UnityEngine.Font.InvokeTextureRebuilt_Internal (UnityEngine.Font font) (at C:/buildslave/unity/build/artifacts/generated/common/modules/TextRendering/TextRenderingBindings.gen.cs:581)

    I can replicate the error often when I change a texture .psd file while Unity is running, and the result will be all dynamic text scrambling its symbols.
    It used to not throw these errors of course, but at some point something was either setup weird in a prefab or on a object, or possibly a script accesses it weirdly, the latter being less conceivable as the stack starts with InvokeTextureRebuilt_Internal.
    I'm currently at a loss because due to not having the source code I can't debug what is going wrong well.

    We are currently on Unity 5.4.0f3, and can't reliably upgrade before Unity has fixed a certain set of issues.

    I'd love to try a version where GenerateMesh started with a null check for this and debug some information to see what it thinks was destroyed.

    Edit: As far as I can tell it's because sometimes a DynamicText was added to TextureRebuilt, but wasn't removed correctly, thus receiving a GenerateMesh() update on a DynamicText that doesn't exist anymore.
     
    Last edited: Jun 24, 2017
  50. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    334
    Hi @DanielSchmidt, thanks for reporting this.

    I will have a look at this. Originally the rebuild callback was made to be "maintained" a bit defensively, removing and re-adding just in case. It's of course possible something is overlooked though.

    If you just upgraded to latest version, do you remember which version you used before? Was the DT or Unity version changed recently before the problems originally started appearing? What platform(s) are you seeing this on?

    When you say it happens when changing texture psd while Unity is running, does this mean that even if you change some unrelated psd (not used in text), the fonts get scrambled? And that the problem doesn't happen runtime when running an actual build?

    Due to nature of this problem, I guess it might be hard to replicate in a small isolated project, but if you can do it, please send it in a zip to contact (at) strobotnik dot com.