This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+9 votes

I need to create a custom signal for a custom control in GDScript.
I see there is a signal keyword, but how do I use it?

in Engine by (29,510 points)

1 Answer

+23 votes
Best answer
extends Node
...
signal my_signal


func _ready():
    connect("my_signal", self, "signal_handler")
    ...
    var otherNode = get_node("someNode")
    otherNode.connect("my_signal", self, "signal_handler")

func SomeFunc():
    ...
    # causes self.signal_handler() to be called
    emit_signal("my_signal")
    ...

func signal_handler():
    ...

edited

by (728 points)
edited by

Ok, so a signal is declared like that :)
I figured out that emit_signal("my_signal") works, but emit my_signal is seen as an error.

Sorry! Edited now.

all you really have to do is this for simpler programs

signal SignalNameHere

then use the editor to connect to target

wherever you want the signal to "emit" put

emit_signal("SignalNameHere")

and voila

I recommend it is used for simpler programs as this requires you to connect the signals when with more complicated ones the program may have to do it itself. So hears the code.

signal SignalNameHere

func  _ready():
emit_signal("SignalNameHere")

https://godotengine.org/qa/user/duke_meister Thank you sieerrr

The most pricise explanation

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.