Signal issues - not emmiting

Godot Version

4.4

Question

Hi Guys,

I’m working on a simple system where the progress bar emits a custom signal when it’s empty or less than 0. The issue I’m currently facing is everything works first time round but when it’s reset via a control node with a script attached the signal doesn’t emit again.

I wanted to ask if I’m missing something fundamental with signals or just the way Godot works or if it’s a bug.

Below is the code for my progress bar

extends ProgressBar
class_name ATBBar

signal barready
var speed = 5.0
var triggered = false

func _ready():
value = max_value

func _process(delta):
value = clamp(value - 10.0 * delta * speed, 0, max_value)
print(“value:”, value, “triggered:”, triggered)

if is_zero_approx(value) and not triggered:
print(“>>> SIGNAL EMITTED”)
emit_signal(“barready”)
triggered = true

func reset_bar():
print(“>>> reset_bar called”)
value = max_value
triggered = false

Below is the code for my control node

extends Control
@onready var atb: ATBBar = $“…/BattleMenu/Player Box/ATB” # ← CORRECT TYPE!

func _ready():
atb.connect(“barready”, Callable(self, “_on_atb_barready”))

func _on_atb_barready():
print(“:heavy_check_mark: yes bar ready”)
atb.reset_bar()

Thanks to anyone who answers or offers their two cents

Hi!

I actually don’t see the issue with your code, but here’s one suggestion: use the native value_changed signal of progress bars.

Something like:

# Connect this to progress bar native signal.

func on_atb_value_changed(value):
    if is_zero_approx(value):
        print('bar ready')

It will be much cleaner to connect a function to this than checking the value in process. And, I believe it will work better, so maybe it will fix the issue too!

2 Likes

Thank you for your reply, I’ve used the built in ones now and they didn’t work. I’ve realised that i was emitting the signal before ‘triggered = true’ once I changed it, it worked!

1 Like