Godot Version
Godot 4.4 (latest)
Question
Sorry if this is a noob question and I’m just wasting your time, but how do you make custom signals with parameters in GDScript?
Godot 4.4 (latest)
Sorry if this is a noob question and I’m just wasting your time, but how do you make custom signals with parameters in GDScript?
The way that i do it its by creating a signal_manager.gd and setting it up as a global in Project Settings > Globals
Inside, i create the signal:
signal_manager.gd:
signal on_points(points: int)
To connect to the signal, i do this:
player.gd:
func _ready() -> void:
SignalManager.on_points.connect(test)
func test(points) -> void:
print(points)
And then, wherever i need to emit the signal, i do this:
test.gd:
func _ready() -> void:
SignalManager.on_points.emit(2)
When i run the game (in this example) the output is:
2
To add to this, signals don’t always have to be global. You can create signals per scene, and you’ll see it in the scenes signal list just like you would for Area2d and other nodes with signals.
You can create the signal by typing “signal SignalName” at the top of your script, the way you add paramaters to your signal is by adding an extra parameter to the emit_signal() function, (ex. emit_signal(“SignalName”,false))
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.