TweenMethod infinitely tweening?

Godot Version

v4.3.stable.mono.official [77dcf97d8]

Question

Hello! I am using C# and have been attempting to Tween multiple portions of an EXP bar UI component from within a script. My TweenProperty and TweenCallback code work perfectly fine, correctly adjusting the expBar’s “scale”, and calling the appropriate function upon completion.

The issue arises with the TweenMethod code. No matter which way I write it, it seems to infinitely tween even though its duration is set to 1 second. The only way it ever ends is if the TweenCallback executes. (So yes, I have tested the TweenMethod code in isolation, and it just infinitely calls its associated Method).

I really have no idea why the TweenMethod code isn’t working, as it and its associated method are essentially just a direct copy of Godot 4’s documentation. (even an exact copy failed in the same way “Tween — Godot Engine (stable) documentation in English”). My code is attached below, any insights would be appreciated, as I have absolutely no idea what could possibly be wrong and have been attempting to fix this for hours.

	int startingExp = unit.exp; // unit.exp is just an Integer
	int endingExp = unit.exp + expGained; // expGained is also an Integer

	Tween tween = GetTree().CreateTween();
	tween.TweenProperty(expBar, "scale", endingVector, 1f); // This works perfectly 
	tween.TweenMethod(Callable.From<int>(UpdateExpLabel), startingExp, endingExp, 1f); // This inifnitely executes in isolation (and only eventually stops when combined with the next line of code)
	tween.TweenCallback(Callable.From(() => expTweenComplete(unit, expGained))).SetDelay(1);
}

public void UpdateExpLabel(int currentExp) {
	// I had a GD.Print() statement here, which showed that this method is just infinitely called by TweenMethod
	expValue.Text = currentExp.ToString(); // expValue is a Label
}

Also, while “infinitely tweening”, the Label “Text” is never updated visually, the changes are only ever visible once the TweenCallback seemingly “ends” the TweenMethod. The reason I know it is infinitely executing is due to a GD.Print statement within the method it is calling, which just infinitely prints the numbers between startingExp and endingExp chaotically, sometimes from ending → starting, sometimes getting stuck within a random range of values, and sometimes in the correct order.

Maybe more than one tween may be calling UpdateExpLabel in the same frame. I suggest killing the current running tween before creating a new one.

2 Likes