#What's the use of Signals in GDScript?

3 messages · Page 1 of 1 (latest)

frosty anchor
#

I watched tutorials and didn't even understand the use of Signals.

weary hornet
#

There are two ways to know when something happened:

  • Ask constantly until it does
  • Wait until someone tells you it did

Asking constantly is certainly a valid approach, but it's a lot slower and repetitive.

Signals allow the latter to happen, where you listen for an event, and then an event goes off and you react.

#

Object A has a signal, "event_happened"
Object B 'connects' to Object A's signal, then goes dormant

Object A's thing happened, so it 'emits' event_happened
Object B, who was listening, wakes up and reacts.

There wasn't any period of time where B was like "did the thing happen? did the thing happen? did the thing happen?"