How to create a custom signal in GDScript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

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?

:bust_in_silhouette: Reply From: duke_meister
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

func signal_handler():


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

Zylann | 2016-04-19 00:28

Sorry! Edited now.

duke_meister | 2016-04-19 00:31

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


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():

Merlin1846 | 2019-11-24 16:17

User duke_meister - Godot Engine - Q&A Thank you sieerrr

The most pricise explanation

Okan Ozdemir | 2020-03-15 19:43