Search Unity

UI Text all Black

Discussion in 'Windows Mixed Reality' started by mavasher, May 29, 2016.

  1. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    I'm still playing around with different capabilities but I'm have a great deal of difficulty with the UI system. I'm very familiar with Unity and have used the UI system extensively for the Android platform. On the 5.4.b16 install that I'm using I cannot change the fonts to any other color other than black.

    I have installed the UI script as instructed here: http://forum.unity3d.com/threads/unity-ui-on-the-hololens.394629/

    And thanks to that code, the gaze functionality works like a mouse pointer, it's able to "mouse-over" and click buttons, etc. Which is really great work.

    I'm not sure why the UI will only allow black text. The color picker in the inspector for the item shows allows me to change the color as reported in the inspector, it's just that the text never actually gets updated and when deployed to the Hololens, it's still black - which is problematic as black is invisible and you have to make sure something bright exists behind it to see anything.

    I've tried deleting and creating new UI elements but it's the same problem.

    Other UI elements allow me to change the color without issue. I've added a new UI material and this doesn't fix anything. I've added a new .ttf file and switched the fontface but this also doesn't allow any other color than black.
     
  2. Subere023

    Subere023

    Joined:
    Apr 27, 2016
    Posts:
    45

    Make sure to put a "Font Material" on the Text element of the UI.
     
    unity_kZmfG-zuqsQ7vg likes this.
  3. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    Thanks. But the new UI material that I put on the object is a "Font Material" - that's didn't work.

    I've never had to create a new material for the textual elements. This seems like a true bug.
     
  4. Subere023

    Subere023

    Joined:
    Apr 27, 2016
    Posts:
    45
    Was it here, in the text element, not its parent, that you added it ? All you have to do is select the circle next to the box and select Font Material from the dialog box that appears. This held me up for a few hours, the exact error you are talking about, turned out to be a really simple fix. quickhelp.png
     
    alfpooh, ZumbaIdol and chulim like this.
  5. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    Hmm... I created my own UI Font material and that didn't work. I didn't realize that they have created a default "Font Material' but not put it on Text elements by Default.

    Thanks - working now. This is crazy - when did this change?
     
  6. raziel_anarki

    raziel_anarki

    Joined:
    Jun 1, 2014
    Posts:
    58
    i "think" this is a bug, but manually dragging the font material from the imported font seems to fix the issue for me too.
     
  7. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    Hello everyone,

    Just a quick tip on the UI gaze control, the lose script from forum post : http://forum.unity3d.com/threads/unity-ui-on-the-hololens.394629/ is not longer needed. we have integrated into unity. You can now add the HoloLens Input Module as a component yo help with gaze, it will also work with UI buttons sliders, etc...

    Looking into the issue with the UI still

    Thank you,
    Wesley
     
  8. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    147
    The stickied "Unity UI on the HoloLens" post has been updated to reflect that you no longer need to download the formerly attached component (and instructions altered to point out that you no longer need to replace Standalone Input Module with HoloLens Input Module, they can and should sit next to each other now). Sorry about any confusion!

    Also, I tried reproducing the text-color issue being pointed out here with and without using that script that used to be attached in http://forum.unity3d.com/threads/unity-ui-on-the-hololens.394629/, and wasn't able to repro either way. Just to make sure, you're saying you're not able to change the color using the field above where you set the material on the text as pointed out in Subere023's screen-cap? Were you able to get the color to show up correctly without replacing the material?
     
  9. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    Correct,
    I create a new Scene. Then go to GameObject | UI | Text which creates the Canvas with a child Text gameObject and an EventSystem gameObject. in the hierarchy.

    The Text component of the Text object does not update color unless the material is changed to "Font Material" - deleting the material after it is applied turns the text black again.

    changing the material to "Font Material" effectively fixes the problem. WIth this fix, there is not problem but it sure was frustrating until I got the fix.
     
  10. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    Hello,

    Could you please file a bug on the issue with a repro project so we can see the issue.

    Please include Detailed Repro steps and Description of the issue.

    Thank you,
    Wesley
     
  11. VincePlusPlus

    VincePlusPlus

    Joined:
    Mar 4, 2015
    Posts:
    6
    Same problem with me. I created a new project to test with Hololens and everything works fine except changing color of a UI Text. Adding a "Font Material" as mentioned above did not work for me, I don't see why i would need to do this if I had never needed to do this in Unity ever before.
     
  12. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    Hello,

    Can you please file a bug with a working repro project so we can see the issue

    Thank you,
    Wesley
     
  13. Harrison_Hough

    Harrison_Hough

    Joined:
    Dec 3, 2015
    Posts:
    43
    Same problem here, text only shows in black and I can't change the colour. Tried both with and without "Font Material" and neither works.

    If I create a fresh unity scene without changing the settings for hololens then the font colours work fine. Once I set up the project for hololens then build for VS I lose the ability to change font colours.
    It might also worth noting that If I have a blank UI Image (white) in a canvas that works fine its just the text element that doesn't.
     
  14. raziel_anarki

    raziel_anarki

    Joined:
    Jun 1, 2014
    Posts:
    58
    i was playing around with shaders, as the font material shader uses az older (i'm guessing IMGUI) shader which doesn't zwrite and/or ztest and so looks bad on worldspace ui-s, and i copy-pasted a custom uitext shader from the builtin shaders, and somehow it started working (you can change text colors, tested in b18/b20), altough i dunno why, as it is the same as the UI-Default/UI-DefaultFont shaders.

    Code (ShaderLab):
    1. Shader "UI/Default Font Fixed"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6.         _Color ("Tint", Color) = (1,1,1,1)
    7.    
    8.         _StencilComp ("Stencil Comparison", Float) = 8
    9.         _Stencil ("Stencil ID", Float) = 0
    10.         _StencilOp ("Stencil Operation", Float) = 0
    11.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
    12.         _StencilReadMask ("Stencil Read Mask", Float) = 255
    13.  
    14.         _ColorMask ("Color Mask", Float) = 15
    15.  
    16.         [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
    17.     }
    18.  
    19.     SubShader
    20.     {
    21.         Tags
    22.         {
    23.             "Queue"="Transparent"
    24.             "IgnoreProjector"="True"
    25.             "RenderType"="Transparent"
    26.             "PreviewType"="Plane"
    27.             "CanUseSpriteAtlas"="True"
    28.         }
    29.    
    30.         Stencil
    31.         {
    32.             Ref [_Stencil]
    33.             Comp [_StencilComp]
    34.             Pass [_StencilOp]
    35.             ReadMask [_StencilReadMask]
    36.             WriteMask [_StencilWriteMask]
    37.         }
    38.  
    39.         Cull off
    40.         Lighting Off
    41.         ZWrite Off
    42.         ZTest [unity_GUIZTestMode]
    43.         Blend SrcAlpha OneMinusSrcAlpha
    44.         ColorMask [_ColorMask]
    45.  
    46.         Pass
    47.         {
    48.         CGPROGRAM
    49.             #pragma vertex vert
    50.             #pragma fragment frag
    51.             #pragma target 2.0
    52.  
    53.             #include "UnityCG.cginc"
    54.             #include "UnityUI.cginc"
    55.  
    56.             #pragma multi_compile __ UNITY_UI_ALPHACLIP
    57.        
    58.             struct appdata_t
    59.             {
    60.                 float4 vertex   : POSITION;
    61.                 float4 color    : COLOR;
    62.                 float2 texcoord : TEXCOORD0;
    63.             };
    64.  
    65.             struct v2f
    66.             {
    67.                 float4 vertex   : SV_POSITION;
    68.                 fixed4 color    : COLOR;
    69.                 half2 texcoord  : TEXCOORD0;
    70.                 float4 worldPosition : TEXCOORD1;
    71.             };
    72.        
    73.             fixed4 _Color;
    74.             fixed4 _TextureSampleAdd;
    75.             float4 _ClipRect;
    76.  
    77.             v2f vert(appdata_t IN)
    78.             {
    79.                 v2f OUT;
    80.                 OUT.worldPosition = IN.vertex;
    81.                 OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
    82.  
    83.                 OUT.texcoord = IN.texcoord;
    84.            
    85.                 #ifdef UNITY_HALF_TEXEL_OFFSET
    86.                 OUT.vertex.xy += (_ScreenParams.zw-1.0) * float2(-1,1) * OUT.vertex.w;
    87.                 #endif
    88.            
    89.                 OUT.color = IN.color * _Color;
    90.                 return OUT;
    91.             }
    92.  
    93.             sampler2D _MainTex;
    94.  
    95.             fixed4 frag(v2f IN) : SV_Target
    96.             {
    97.                 half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
    98.                            
    99.                 color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
    100.  
    101.                 #ifdef UNITY_UI_ALPHACLIP
    102.                 clip (color.a - 0.001);
    103.                 #endif
    104.  
    105.                 return color;
    106.             }
    107.         ENDCG
    108.         }
    109.     }
    110. }

    i'm also including the .mat file, as the parameters it contains from other shaders before i set this one may be of relevance to the devs.

    Code (YAML):
    1. %YAML 1.1
    2. %TAG !u! tag:unity3d.com,2011:
    3. --- !u!21 &2100000
    4. Material:
    5.   serializedVersion: 6
    6.   m_ObjectHideFlags: 0
    7.   m_PrefabParentObject: {fileID: 0}
    8.   m_PrefabInternal: {fileID: 0}
    9.   m_Name: UIText
    10.   m_Shader: {fileID: 4800000, guid: fe61b015b2c4be54eb75b46a0c7be657, type: 3}
    11.   m_ShaderKeywords: _EMISSION
    12.   m_LightmapFlags: 1
    13.   m_CustomRenderQueue: 3000
    14.   stringTagMap: {}
    15.   m_SavedProperties:
    16.     serializedVersion: 2
    17.     m_TexEnvs:
    18.     - first:
    19.         name: _BumpMap
    20.       second:
    21.         m_Texture: {fileID: 0}
    22.         m_Scale: {x: 1, y: 1}
    23.         m_Offset: {x: 0, y: 0}
    24.     - first:
    25.         name: _DetailAlbedoMap
    26.       second:
    27.         m_Texture: {fileID: 0}
    28.         m_Scale: {x: 1, y: 1}
    29.         m_Offset: {x: 0, y: 0}
    30.     - first:
    31.         name: _DetailMask
    32.       second:
    33.         m_Texture: {fileID: 0}
    34.         m_Scale: {x: 1, y: 1}
    35.         m_Offset: {x: 0, y: 0}
    36.     - first:
    37.         name: _DetailNormalMap
    38.       second:
    39.         m_Texture: {fileID: 0}
    40.         m_Scale: {x: 1, y: 1}
    41.         m_Offset: {x: 0, y: 0}
    42.     - first:
    43.         name: _EmissionMap
    44.       second:
    45.         m_Texture: {fileID: 0}
    46.         m_Scale: {x: 1, y: 1}
    47.         m_Offset: {x: 0, y: 0}
    48.     - first:
    49.         name: _MainTex
    50.       second:
    51.         m_Texture: {fileID: 0}
    52.         m_Scale: {x: 1, y: 1}
    53.         m_Offset: {x: 0, y: 0}
    54.     - first:
    55.         name: _MetallicGlossMap
    56.       second:
    57.         m_Texture: {fileID: 0}
    58.         m_Scale: {x: 1, y: 1}
    59.         m_Offset: {x: 0, y: 0}
    60.     - first:
    61.         name: _OcclusionMap
    62.       second:
    63.         m_Texture: {fileID: 0}
    64.         m_Scale: {x: 1, y: 1}
    65.         m_Offset: {x: 0, y: 0}
    66.     - first:
    67.         name: _ParallaxMap
    68.       second:
    69.         m_Texture: {fileID: 0}
    70.         m_Scale: {x: 1, y: 1}
    71.         m_Offset: {x: 0, y: 0}
    72.     m_Floats:
    73.     - first:
    74.         name: _BumpScale
    75.       second: 1
    76.     - first:
    77.         name: _ColorMask
    78.       second: 15
    79.     - first:
    80.         name: _Cutoff
    81.       second: 0.5
    82.     - first:
    83.         name: _DetailNormalMapScale
    84.       second: 1
    85.     - first:
    86.         name: _DstBlend
    87.       second: 0
    88.     - first:
    89.         name: _GlossMapScale
    90.       second: 1
    91.     - first:
    92.         name: _Glossiness
    93.       second: 0.5
    94.     - first:
    95.         name: _GlossyReflections
    96.       second: 1
    97.     - first:
    98.         name: _Metallic
    99.       second: 0
    100.     - first:
    101.         name: _Mode
    102.       second: 0
    103.     - first:
    104.         name: _OcclusionStrength
    105.       second: 1
    106.     - first:
    107.         name: _Parallax
    108.       second: 0.02
    109.     - first:
    110.         name: _SmoothnessTextureChannel
    111.       second: 0
    112.     - first:
    113.         name: _SpecularHighlights
    114.       second: 1
    115.     - first:
    116.         name: _SrcBlend
    117.       second: 1
    118.     - first:
    119.         name: _Stencil
    120.       second: 0
    121.     - first:
    122.         name: _StencilComp
    123.       second: 8
    124.     - first:
    125.         name: _StencilOp
    126.       second: 0
    127.     - first:
    128.         name: _StencilReadMask
    129.       second: 255
    130.     - first:
    131.         name: _StencilWriteMask
    132.       second: 255
    133.     - first:
    134.         name: _UVSec
    135.       second: 0
    136.     - first:
    137.         name: _UseUIAlphaClip
    138.       second: 0
    139.     - first:
    140.         name: _ZWrite
    141.       second: 1
    142.     m_Colors:
    143.     - first:
    144.         name: _Color
    145.       second: {r: 1, g: 1, b: 1, a: 1}
    146.     - first:
    147.         name: _EmissionColor
    148.       second: {r: 0, g: 0, b: 0, a: 1}
     
    Roiw likes this.
  15. Harrison_Hough

    Harrison_Hough

    Joined:
    Dec 3, 2015
    Posts:
    43
    Awesome I just added in that Shader and now I can edit the colour.

    Thanks!
     
  16. Hash-Buoy

    Hash-Buoy

    Joined:
    Jan 4, 2014
    Posts:
    19
    Right click on the font , and re import . This fixed the issue for me.
     
  17. ShayneK

    ShayneK

    Joined:
    Jan 19, 2017
    Posts:
    4
    Just a FYI that this is still an issue. I can't change the font colour either and I have no default "Font Material".
     
  18. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    298
    Having this problem, any idea ?
     
  19. ZumbaIdol

    ZumbaIdol

    Joined:
    Aug 24, 2018
    Posts:
    1
    Thank you! I couldn't figure out why the text went dark after clicking the play button to test my button...a great time saver!
     
  20. CHJ_S

    CHJ_S

    Joined:
    Aug 29, 2018
    Posts:
    1
    So I had the issue with black text only...if you are using multiple monitors, the palette for this was coming up on another monitor (main, I have 3, but I use the main one for help searches and instructional video) under other windows that were open. Worth a check if nothing else is working.
     
  21. ryo0ka

    ryo0ka

    Joined:
    Sep 27, 2015
    Posts:
    32
    @raziel_anarki Your shader worked out for me. I was scratching my head for hours.

    Thank you for sharing the solution.
     
  22. Bayaba

    Bayaba

    Joined:
    Sep 16, 2015
    Posts:
    1
    I still have this problem 2019.1.0f2 Pro ver.

    1. Build your project.
    2. All text colors would be changed black.
    3. Uncheck "Canvas" object in inspector.
    4. Check "Canvas" object again in inspector.
    5. Save your project.
    6. The problem will be gone.

    I always use this way to fix the problem. But I don't know why. lol