Hi!
I’ve been reading a lot of forums and discussions in regards to converting a number to string garbage free.
At the moment any of my attempts to display a number in a UI.Text text created garbage, so this triggered the Garbage Collector and I get some performance hiccups on mobile when that happens.
Basically, I want to display the number of coins the player collected and sometimes he can collect more of them in quick succession. That is when the hiccups occur.
Basically:
myUIText.text = myIntValue.ToString();
Generates garbage.
Using StringBuilder is no good either, because this one generates garbage when converting ToString()
A popular fix is generating all the strings before hand and just placing those in the UI.Text.text field.
string[] allNumbers = new string[100] {"1", "2", .... etc};
myUIText.text = allNumbers[myIntValue];
But this is not good when you have a big range of numbers.
I saw some other clever tries to fix this, but some of them are obsolete nowadays for some reason.
Is there any way to display a number in UI.Text without garbage being generated?