0 votes

I have a bunch of area2d nodes with collision shapes. And I want for them to emit a signal when they are entered. How do I do that with code?
I understand how to connect a signal or how to pass data by a custom signal. But how do I emit build_in signals?

Godot version 3.4
in Engine by (88 points)

1 Answer

+1 vote
Best answer

For built in signals the signal is automatically emitted when the event occurs and the function that you assigned to be the callback via connect() (or in editor) will be called. If you want to emit your own custom signal when a mouse enters your Area2D simply emit it in the callback:

extends Area2D

signal my_custom_signal

func _ready() -> void:
    self.connect("mouse_entered", self, "_on_Area2D_mouse_entered")

func _on_Area2D_mouse_entered() -> void:
    print("I'm automatically called when a mouse enters my Area2D.")
    emit_signal("my_custom_signal")
by (3,768 points)
selected by

Thanks. That is what I assumed at first. But it turned out my debug console wasn't working properly because I changed its remote port number. So I couldn't see that what I tried actually worked...

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.