Search Unity

UI missing in Windows game, is visible in scene view (is visible in both game and scene view on OSX)

Discussion in 'UGUI & TextMesh Pro' started by DMeville, Jul 2, 2016.

  1. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I have the most frustratingly difficult to debug, strangest issue I've ever had with unity.
    *Some* of my UI is disappearing in the game view, but they are visible in the scene view, and this only happens on windows. Everything is working 100% in OSX, there is no missing UI in OSX.

    I usually work and test on OSX. But yesterday I made a weekly Windows build to test some things and noticed that some of my UI elements were missing (that were previously working 100% on windows last week.) I then proceeded to download the Windows editor so I could get a better idea of what's going on and still I have no idea. I downloaded the latest version of Unity to see if it was some bug that was fixed, but this problem still persists on the latest windows version of Unity (Windows 5.3.5f1).

    missingrendertexture.png

    Here's my first image. Left is scene view, right is game view on windows. All those UI elements are siblings of the same canvas. All the text is TextMeshProUGUI text (but that all works without problems here). The face that is missing in the game view is a UnityEngine.UI Image component with no sprite attached, and a material (that is an Unlit texture that reads in a RT from a separate camera).
    The missing Y button is a simple UnityEngine.UI Image component with a sprite on it and the "sprites-default" material.
    EDIT: Removing the material from this Image fixes this "Y" image from disappearing

    missing text.PNG
    Left is scene view, right is game view on windows. All the UI elements (green circles, and text, and the "A" on the top-left corner) are all siblings of the same canvas.
    The A button is a simple UnityEngine.UI image component with a sprite on it (100% the same as the MISSING Y button from the image above, but here it's visible (what!?))
    The "57" text is a TextMeshProUGUI component (and 100% the same as the TEXT from the imag above (what!?)


    Missing UI Text 1.PNG
    Left is scene view, right is game view on windows. All the UI elements are all siblings of the same canvas (black panel, text)

    The text circled is TextMeshProUGUI text, the text below is UnityEngine.UI Text.

    missing transition.PNG
    Left is scene view, right is game view on windows. All the UI elements are all siblings of the same canvas (black panel, text, logo images)
    Here all the text is TextMeshProGUI text as well, but it's all visible here.
    The "Black fade transition" is a UnityEngine.UI Image with no sprite but a material, with a custom shader that fades in/out based on a slider. This transition happens in/out between every scene change, but only *sometimes* it's missing. (in this screenshot there is a slight vignette on the game camera, but there is also a black transition that's faded in the middle, horizontally with soft black bars on the top and bottom.

    I'm pretty confused. Again, this only seems to happen on Windows, the scene view and game view on OSX is 100% identical and all my UI is there on OSX. No errors are ever logged to the console. Sometimes things "pop" back into existence, but nothing specific does this (or at least I can't reproduce it).
    I thought that it might be TextMeshPro, but as you can see there's lots of working TextMeshPro text all over the UI.
    I thought it might be Images with no sprites and only materials (like the face, or the transition), but then why would my "Y" button disappear from the first image (it's an image with a sprite and no material!)

    Does anyone have any idea what's going on?
     
    Last edited: Jul 2, 2016
  2. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    not sure.. but did you try changing the Shader to another? Same effect?
     
  3. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @IzzySoft Just tried that - no change for the better. In fact some MORE (entirely unrelated) ui elements are now missing.
    ...As soon as I tried to take a screenshot the newly missing UI popped back into existence, what the heck?

    The ui that was previously missing in the images above are still missing though, even after changing the shaders on the objects where applicable (as some of the missing ui's don't have materials and are just sprites, etc)

    EDIT: I tried changing it to the "Standard" shader before, didn't realize Images needed specific shaders (from the UI category), changing the shader to UI/Unlit/Transparent fixes my missing render texture images and button images.

    I'll have to write a new custom shader that follows the "UI requirements" (which are not documented anywhere...) to fix my transition issue I think. Still missing half of the text though..
     
    Last edited: Jul 2, 2016
  4. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
  5. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I may have figured out part of the issue. It seems all my images that were disappearing had materials set on the Image component, removing these materials (or using a shade for the UI category) prevents those images from disappearing. I can fix this on the "Y" button on the first image (as it doesn't need a sprites-default material to render how I wish), and the render texture face (changing it to UI/Unlit/Transparent).

    This doesn't solve my issue though, because some of my Image components display renderTextures from separate cameras (and I need a material to set the renderTexture for the Image component to render it properly) Need to use UI shader.

    I'll need to write a custom shader to fix my UI transition stuff though, doesn't seem like the UI shader requirements are documented anywhere though.

    Perhaps the TextMeshProUGUI component does something similar with images/materials internally, but it doesn't really explain why only some of the TextMeshPro texts disappear, and why things are still visible in the scene view, but only gone from the game view, and only on windows. Because of that I'm not convinced TextMeshPro is causing the issue for text.
     
    Last edited: Jul 2, 2016
  6. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Thanks for posting on the TextMesh Pro user forum as I would not have even been aware of your post here. Please take a look at my last reply and let me know if (for testing purposes) using a different Font Asset or Material Preset on the text objects using the Mesh Renderer does result in the text showing up again.

    I suspect the issue is simply related to mixing TMP UI text objects with TMP text objects using the Mesh Renderer where these two groups of objects share the same Font Asset and / or Material Presets. Essentially you end up with 2 groups of objects which share the same material fighting over ZTest settings and also affected by Dynamic Batching.

    The TMP UI text objects (assuming the Canvas is set to Overlay mode) are using ZTest Always whereas the other text objects in World Space are trying to use ZTest (LEqual).

    Any easy solution is to use a different Material Preset for each group. In the Editor, simply create a new Material Preset for world space use. I would name these something like "Arial SDF - Drop Shadow - WS" and the other "Arial SDF - Drop Shadow - OS".

    If these are setup via scripting then I would create a material instance for each group which would also make it possible for them the Dynamically batch with the other text objects that share these materials.
     
  7. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Stephan B Thanks, that seems to have been the issue! I made a new font and using that for the worldspace TMP text and no text is disappearing anymore!

    Super weird how this only happens in windows, and in the game view (and not in the scene) though, but I'm glad the fix was something relatively simple! Thanks a million!

    So all my issues have been fixed now, for anyone who stumbles on this thread looking for answers:
    - TMP needs a separate font asset for worldspace and screenspace text, otherwise they fight!
    - UnityEngine.UI Images need either no material, or a material from the UI shader category otherwise they disappear
    - My transition needed a bit of editing, changes just included adding "ZTest Off" to the shader, seems to have worked.
     
  8. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    You only need to use separate Material Presets. Not separate Font Assets as this would result in duplication of resources which is unnecessary. See the following video about Working with Material Presets.

    This is only necessary when mixing normal TMP objects which use the Mesh Renderer and TMP UI objects that use the Canvas when they share the same Material Presets.

    Note: Using a mix of TMP UI objects that use a Canvas in WorldSpace or CameraSpace along with other TMP UI objects using a Canvas in ScreenSpace Overlay will work fine.
     
  9. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Stephan B: Ok that's even easier! Thanks for clearing that up!
     
  10. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    And much more efficient as you can have dozen's or even 100's of Material Presets giving you all kinds of different treatments and styles all using the same SDF Font Asset.

    Here is a simple example where I used the Snap It! SDF Font Asset and created a few Material Presets to give it different looks.

     
    Last edited: Jul 4, 2016
    DMeville likes this.