0
\$\begingroup\$

I have a Unity project which requires a bunch of Canvases and, surprise surprise, they're creating a lot of lag. I've already turned off the graphics raycaster for every single one, but they still drop so many frames.

Are there any good alternatives to draw text in the worldspace that are a lot more efficient? (I'm targeting mobile, so this is important).

\$\endgroup\$
3
  • \$\begingroup\$ Can you give us some examples of what you're trying to accomplish? Is there a limited set of specific phrases you need to render, or do the texts need to be fully dynamic? \$\endgroup\$
    – DMGregory
    Commented Jul 23, 2017 at 15:10
  • \$\begingroup\$ So I right now I'm grabbing a lot of data from a JSON object, and loading it into the canvases. However, eventually, the JSON data will change every 10 minutes or so, so there needs to be some level of updating. \$\endgroup\$ Commented Jul 23, 2017 at 15:43
  • \$\begingroup\$ Use frame debugger or renderdoc to see what is happening in your canvas call. it might be a batching problem. \$\endgroup\$
    – Sidar
    Commented Jul 23, 2017 at 15:58

3 Answers 3

2
\$\begingroup\$

Although I don't have experience with third-party alternatives, if you're experiencing performance issues with canvases there are a couple things you might want to try before deciding on switching to a different UI system:

  • Canvases generate meshes that are recalculated whenever an item within the canvas changes. This can cause performance issues if it's occurring every frame. Try to separate the dynamic elements that will change every frame into their own canvas (or separate ones) so that they won't dirty the canvases with static objects.

  • If you're using a World Space Canvas, be sure to set it's Event Camera. If you leave it blank, it will try to get the default camera by calling Camera.main every frame, which searches your scene for the Camera with the "MainCamera" tag. This can cause performance issues in scenes with large tagged objects or mobile.

  • Particularly on mobile, rendering images with lots of transparent pixels can cause a performance hit.

  • In some cases, having "Pixel Perfect" checked can cause performance issues.

  • If your issue is with text rendering with a custom font, ensure that the font size isn't set too high. The font texture that Unity generates may be an unnecessarily high resolution.

If you're still having issues, you can use Unity's profiler to find out what exactly is taking too much time.

\$\endgroup\$
1
  • \$\begingroup\$ This pretty much hits all of the points I've seen in various Unity talk videos about performance. #1 is always canvas and how it's optimized in a particular way and that way is not how people use it intuitively. \$\endgroup\$ Commented Jul 23, 2017 at 20:16
0
\$\begingroup\$

One alternative would be to use text meshes. These are texts which are rendered to 3d objects which can then be placed in world space.

The technical implementation of a text mesh is just a quad with a texture which is generated at runtime when the text-string is set. So the resource cost for a text mesh is just two polygons and one texture.

\$\endgroup\$
2
  • \$\begingroup\$ AFAIK, TextMeshes generates one quad (two polygons) for every letter in your string. But I think only one render pass is needed for all the generated quads. \$\endgroup\$
    – Hellium
    Commented Jul 23, 2017 at 17:23
  • \$\begingroup\$ I'm going to try this for now and see how it goes. \$\endgroup\$ Commented Jul 24, 2017 at 1:25
0
\$\begingroup\$

you could also just use a GUIText component its still there just a little hidden in newer versions of unity, just create an empty gameobject in your hierarchy then click the add component button in the inspector go to rendering and choose GUIText. I use them all the time for things like npc or player name banners as they can be rotated to always face the camera and such, and I've not ever seen any performance hit in using them. and to clarify a GUIText is similar to a Text Mesh in its options, but not the same thing. a GUIText does not use a mesh renderer its rendered differently and I have found in my experience its less of a performance hit.

\$\endgroup\$

You must log in to answer this question.

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