How to tween texture progress bar

Godot Version

4.5.1

Question

I have this script:

@onready var anim_texture_progress_bar: TextureProgressBar = #node



## anim buttons, update progress when pressed
# update progress bar by 10%
func _on_anim_little_pressed() -> void:
	save_data.current_anim_progress += 10.0
	
	var tween = create_tween()
	tween.tween_property(anim_texture_progress_bar, "value", save_data.current_anim_progress, 1.0).from_current()

	
	pass # Replace with function body.

I’m trying to make it so when a button is pressed a value is updated in the save file and the the bar value is tweened to the updated one. Currently my result is a snap from the current position to the end. I tried adjusting the duration but even at 10 seconds it just snaps instantly.

Put a print statement or a breakpoint in that function to see how many times it gets called

Did you set the progress bar’s max value to 100? I think it’s 1.0 by default (?)

the default is 100.0, its a texture progress bar

it gets called once, (hi btw)

What happens if you tween something else?

The only thing in the scene is ui nodes.

I tried tweening the control node, the 1st node, it tween’s just fine.

func _ready() -> void:
	var tween = create_tween()
	tween.tween_property(self, "position", Vector2(100.0, 100.0), 1.0).from_current()

Print save_data.current_anim_progress

func _on_anim_little_pressed() -> void:
	print('1: ', save_data.current_anim_progress)
	print('1: ', anim_texture_progress_bar.get_value())

	save_data.current_anim_progress += 10.0

	print('2: ', save_data.current_anim_progress)
	print('2: ', anim_texture_progress_bar.get_value())

	var tween = create_tween()
	tween.tween_property(anim_texture_progress_bar, "value", save_data.current_anim_progress, 1.0).from_current()

	print('3: ', save_data.current_anim_progress)
	print('3: ', anim_texture_progress_bar.get_value())
#pressed
1: 0.0
1: 0.0
2: 10.0
2: 0.0
3: 10.0
3: 0.0
#pressed
1: 10.0
1: 10.0
2: 20.0
2: 10.0
3: 20.0
3: 10.0
#pressed
1: 20.0
1: 20.0
2: 30.0
2: 20.0
3: 30.0
3: 20.0

I clicked the button 3 times

Not from _ready(). Try it from the signal handler.

1 Like

Just guessing - perhaps it is updating the value but not emitting the value_changed signal during the tween so the texture doesn’t animate.

Can test this by printing the value inside of _process or _physics_process to see if it updates smoothly or all at once.

Another thing that might want to keep in mind is the Step value which defaults to 1.0 which is constantly rounding your values.

1 Like
func _on_anim_little_pressed() -> void:
	
	
	save_data.current_anim_progress += 10.0
	
	#var tween = create_tween()
	#tween.tween_property(anim_texture_progress_bar, "value", save_data.current_anim_progress, 1.0).from_current()
	
	var tween = create_tween()
	tween.tween_property(self, "position", Vector2(100.0, 100.0), 1.0).from_current()

Works fine, tweens as expected

Try printing value in _process() as @salmon_jammin suggested.

1 Like
pressed
process: 0.0
process: 0.0
process: 0.0
process: 10.0

Yeah it seems to just jump straight to the value. The step size is set to 0.01.

You’ll need to provide more information. Can you make a minimal project that reproduces the problem?

Its a zip with the tsn and the scripts and images needed attached. Let me know once you’ve downloaded it so I can take it down.

That’s not minimal.

what do you want me to do? please explain what you mean by minimal

Reconstruct the problem from scratch in a fresh empty project.

1 Like

put return at the start of _on_anim_texture_progress_bar_value_changed()

1 Like