Hi all -
I was wondering if there’s a best practice in terms of handling text-heavy UI elements (for mobile devices) that the user interacts with only occasionally (think your typical store screen, which gets pulled up when needed but which remains out of sight for the better part of the game).
As far as I can tell, there are two ways to handle them (or are there more), though each has drawbacks:
- Enable/Disable as needed - self-explanatory, really - if you don’t need it, gameObject.SetActive(false). The upside is that, presumably, it doesn’t consume any memory while deactivated and potentially allows for some - sparing - use of LateUpdate(). The downside is… good lord, the garbage! Enabling/disabling text alone inevitably generates garbage, and that’s before you even start to account for concatenation (of which there’s a lot going on, for example, when type double values such as 10,000,000 have to be converted to 10.00M for display purposes, etc).
- Hide/Tuck it away somewhere/set scale to 0 - doesn’t disable anything, but hides it instead. The upside is that the garbage price of activating everything has to be paid only once, at the very start of the game, and animations are somewhat easier to set up. The downside is that you have to be even more careful with what you put into Update (honestly, I barely use it, and even then only on a conditional basis, so it’s not a big deal), that presumably the object sitting there still generates draw calls and hogs up memory, that you might have to throw your event listening system out of the window now that half your listeners are inactive, and, generally, that it seems to fly in the face of only keeping in memory things that you actually need.
How do you handle such things in your games? Looking forward to your feedback.
Cheers,
George