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.
0 votes

I was wondering what is the ordering of the execution between signals. For instance, if when signal A is emitted will all methods connected to it be called before another signal is handled.

For instance, if signal A is emitted and one of the method connected to it emits a signal B, will all methods connected to signal A be called before any methods connected to signal B ?

Godot version 4 beta10
in Engine by (14 points)

very likely so, signals are handled almost immediately. Signal A should be received in the same frame for all listeners.

1 Answer

0 votes

If a signal function emits a signal, that signal is processed before another signal on the same level.
Here is how I tested it (a 2d project with a button where the function test() is called from the button.pressed() signal):

extends Node2D
signal signalA
signal signalB
signal signalC

func _ready():
    connect("signalA", self, "sigA")
    connect("signalB", self, "sigB")
    connect("signalC", self, "sigC")
func test(): 

func _on_Button_pressed():

func sigA(): 

func sigB(): 

func sigC(): 

This prints:

by (376 points)

Thank you for your answer,

I did some tests based on your example and these confirm (at least experimentally) that a signal is processed as soon as it is emitted (in your example, the methods connected to signal C will be called before any remaining methods connected to signal A not called).

This makes sense from an implementation point of view since signals are Godot's version of the observer pattern.

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.