Emit_signal always fails wih ERR_UNAVAILABLE

Godot Version 4.2.1

Question

I have a script with these signals defined, but emit_signal always returns ERR_UNAVAILABLE for one and never for the other:

signal dash_started(pos: Vector2)
signal dash_cooldown_ended(pos: Vector2)

# ... cut ...

func _dash(direction: Vector2) -> void:
	# ... cut ...
	_dash_cooldown_timer.start()
	var err: Error = emit_signal("dash_started", position)
	assert(err == OK) # this always works
	await _dash_cooldown_timer.timeout
	_is_dashing = false
	err = emit_signal("dash_cooldown_ended", position)
	assert(err == OK) # this always fails

When I check in the debugger err is 2, that would be ERR_UNAVAILABLE.

The doc for emit_signal says:

Returns @GlobalScope.ERR_UNAVAILABLE if signal does not exist or the parameters are invalid.

I’m fairly sure I’m just missing something obvius here, but why the first emit_signal always works and the second one always fails?

Try dash_cooldown_ended.emit(position)

1 Like

Did you free the object in the time it took it to await for the timeout?

The object being freed should fail otherwise, not by that way, it should cause a segfault

That was it, thanks.

I didn’t know that in Godot 4 there’s a new way to emit signals, thanks.

Weird that emit_signal failed like that though, should I open an issue?

1 Like

Make sure first the code uses the correct name

Yep, I copy-pasted the string to double check.

If I can create a minimal reproducible example I’ll open an issue. Never mind, looks like it’s deprecated syntax and the new one is just better all around.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.