Animate counting number inside a label node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi. What would be the recommended way to animate a ‘counter’ to count up from 0 to a specific number (ideally with an ease-in effect)? I want to show scores at the end of the level. My main GUI node (which is a control node) has a bunch of labels which display numbers stored in variables. It would look much cooler if each score could animate/calculate up to the scored number, as opposed to just fading in or some such. Can anyone help?

:bust_in_silhouette: Reply From: andersmmg

You’d probably want to attach a script to the label with a current number variable and a target number variable. Just check if the target is higher than the current one and increment the current variable if it is. You could also have the speed depend on the distance to the target for a smoother animation.

Yea, but how? I tried with a tween and anim player - neither of these animate the text property of a label node…:frowning:

Macryc | 2020-03-15 12:46

With a script. It’s not possible to animate a string. Just do something like $Label.text = “whatever” to set it’s value, and you can use the str() function to change the number to a string to put it in the label.

andersmmg | 2020-03-15 19:42