Why is my texture progress bar not working/updating?

Godot Version

Godot v4.3.stable.official

Question

[FIXED BUT I HAVE NO IDEA WHY IT DIDNT WORK, CAN SOMEONE EXPLAIN? - COMMENTS]

I am making a fighting 2d game with bird view. I wanted to do health with progress bar for the first time and in my logic everything should be fine but bar doesnt update(always looks like max value)

extends CharacterBody2D
class_name mc
@onready var animacja: AnimationPlayer = $Postac/AnimationPlayer
var zycie
var maxzycie
var uderzony = false
@onready var hp: TextureProgressBar = $"../HP"
var speed = 200  # speed in pixels/sec
@onready var postac: AnimatedSprite2D = $"../Barbarzynca/Postac"

# Referencja do AnimatedSprite2D
@onready var Postac: AnimatedSprite2D = $Postac

func _ready() -> void:
	print(hp)
	maxzycie = 10 + Global.zdrowie1
	zycie = maxzycie
	hp.min_value = 0
	hp.max_value = maxzycie

func _physics_process(delta):
	await get_tree().physics_frame 
	var direction = Input.get_vector("Left", "Right", "Up", "Down")
	velocity = direction * speed
	move_and_slide()
	if direction.x > 0:
		if Global.skin1 == 1:
			Postac.play("Prawo1")  
		if Global.skin1 == 2:
			Postac.play("Prawo2")  
		if Global.skin1 == 3:
			Postac.play("Prawo3")  
	elif direction.x < 0:
		if Global.skin1 == 1:
			Postac.play("Lewo1")  
		if Global.skin1 == 2:
			Postac.play("Lewo2")  
		if Global.skin1 == 3:
			Postac.play("Lewo3")  
	elif direction.y > 0:
		if Global.skin1 == 1:
			Postac.play("Dol1")  
		if Global.skin1 == 2:
			Postac.play("Dol2")  
		if Global.skin1 == 3:
			Postac.play("Dol3") 
	elif direction.y < 0:
		if Global.skin1 == 1:
			Postac.play("Gora1")  
		if Global.skin1 == 2:
			Postac.play("Gora2")  
		if Global.skin1 == 3:
			Postac.play("Gora3") 
	else:
		Postac.play("Dol1")  
	if Input.is_action_pressed("Down") or Input.is_action_pressed("Up") or Input.is_action_pressed("Right") or Input.is_action_pressed("Left"):
		animacja.play("Chodzenie")
	else:
		animacja.play("RESET")

func _process(delta: float) -> void:
	hp.value = zycie

func _on_area_2d_body_entered(body: Node2D) -> void:
	if uderzony == false:
		if body is Przeciwnik:
			uderzony = true
			body.dmg()
			if  zycie > 0:
				zycie = zycie - body.obrazenia
				if zycie < 0:
					zycie = 0
			print(zycie)
			hp.value = zycie
			hp.queue_redraw()
			print (hp.value)
			postac.modulate = Color(1, 0, 0)  # Nakładamy czerwony kolor
			await get_tree().create_timer(0.1).timeout
			postac.modulate = Color(1, 1, 1)  # Przywracamy normalny kolor
			uderzony = false

(sorry for other language)
,uderzony = hit
zycia = health
maxzycie = maxhp

I added prints to check variables and:

  • damage is dealt normally - player recives damage(variable zycie is decreasing
  • the same applies to value of texture progressbar - the value is decreasing but it doesnt look like it when i lunch the game
  • if in editor, i change value ,current" progressbar changes(but sadly not in game)
  • also path to hp(texture progressbar) is good(the current value of progressbar changes)
  • values all time are between min and max values

Is this bug or am i forgetting something?

Hey! I might not be of great help but I remember it happened to me too a while back…
My issue was the texture I used in my texture progress bar… (I don’t remember right now, but they were either too small or too big…)
Maybe you can test with a “normal” progress bar to see if it’s the logic or the textures?

1 Like

I fixed it. Turned out that _process function didn’t work at all. I just move its one line to other function Can someone explain why?