Archive 17/01/2023.

[SOLVED]Text Attribute Animation

Bluemoon

Having learned how to use Urho3D’s attribute animation, I tried to animated the text attribute of a Text UI element to obtain the effect of the text changing based on keyframe like the code below but it didn’t work out and no errors were thrown or logged

ValueAnimation@ textAnimation = ValueAnimation();
		
textAnimation.SetKeyFrame(0.0f, Variant(String("1")));
textAnimation.SetKeyFrame(1.0f, Variant(String("2")));
textAnimation.SetKeyFrame(2.0f, Variant(String("3")));

Text@ text = ui.root.CreateChild("Text");
//Other initialization procedures here...

text.SetAttributeAnimation("Text", textAnimation, WM_ONCE);

I tried animating the color attribute and it worked out well

can the text attribute of a Text UI be animated, since it is an attribute I thought all attributes of Animatables can be animated

hdunderscore

Looks like this is caused by the text attribute being set up like this:

Because it’s setting to the variable directly, instead of calling through SetText/GetText, it doesn’t call the UpdateText method. Eg, if you do this in an update event:

You’ll see the animation is working, just not updating automatically.

weitjong

I believe this can be considered as a bug. Some of the attributes, such as Text’s text attribute, need the ApplyAttributes() method to be called on the instance being changed in order to make it effective. Current attribute animation implementation may have forgotten to do so. When changing the Text’s text attribute in the attribute inspector window in the editor, the changed text is reflected immediately correctly because it calls the ApplyAttributes() method somewhere in the inspector’s edit function.

weitjong

I have fixed this bug in the master branch. I have also modified the 30_LightAnimation samples to test out the text attribute animation.

Bluemoon

Thats great, I’ll grab the master branch later during the day and test it out. Thanks a million

Bluemoon

Sorry for the late reply… it works well now. Thanks once more :smiley: