0
\$\begingroup\$

I have two SpriteRenderers in a Canvas with a Text object in front. They work as expected, with the Text being on top and the two SpriteRenderers showing through from behind it, except for some occasions when the Text is updated from a script, in which case the Text is no longer visible

From playing around it seems that the Text is visible as long as it's covered less than 50% by one of the SpriteRenderers behind, even when the Text's Z-index is set to be far closer to the Camera than the SpriteRenderers

Video

Any help, suggestions, or even just keywords to google should be super helpful, thanks!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Do you observe this only in the scene view when looking at the text diagonally as shown here, or does it also occur in the game view when looking directly along the z axis? \$\endgroup\$
    – DMGregory
    Commented Oct 24, 2022 at 21:51
  • 1
    \$\begingroup\$ Also, when using a Canvas for layout, you likely want to use Image components rather than SpriteRenderers, and TextMeshProUGUI components over Text. These use the UI canvas layout system which also helps control the draw order. \$\endgroup\$
    – DMGregory
    Commented Oct 24, 2022 at 21:52
  • \$\begingroup\$ Thanks for your responses, I'm seeing it in the game view as well. I'll try swapping out for those UI specific components and see if it solves my problem, if so please post your response as an answer so I can fill your pockets with precious reputation points :-) \$\endgroup\$
    – Harold
    Commented Oct 25, 2022 at 9:36
  • \$\begingroup\$ Yep, swapping out just the SpriteRenderers for an Image solved my problem. Thanks so much! \$\endgroup\$
    – Harold
    Commented Oct 25, 2022 at 9:39
  • 1
    \$\begingroup\$ Be sure to post your solution as an Answer below! I've got way more rep than I should have already. \$\endgroup\$
    – DMGregory
    Commented Oct 25, 2022 at 12:18

1 Answer 1

0
\$\begingroup\$

Big thanks to DMGregory, my issue was using a SpriteRenderer rather than a UI image and that was causing my Text to be hidden

Switching out to an image solved that problem for me. Thanks again!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .