0 votes

I'm using the Area2D and the signal i need gives an Object variable, how can i access it using the connect() function(or another one)

in Engine by (1,193 points)

I don't understand well your question.

Area2D sends you a signal and you can handle it like this, for example:

func _ready():
    area2d.connect("area_enter", self, "_on_object_enters_area")
    # Note: you can also connect the signal from the editor

func _on_object_enters_area(obj):
    # Do stuff with obj

Well how do i get the object reference from the signal to the function to do code stuff with it?

1 Answer

+1 vote
Best answer

Guides/Info about signals:

The variable is just sent.

when you see a signal described in the documents like this: area_enter ( Object area ) . The things between the ( ) are automatically sent.

All you have to do is connect your signal with connect() and then give room for the variables in the function that is being called.


func signalTriggerThis(area):

You can also add variables to a signal.
with extra vars: connect("area_enter", self, "_on_object_enters_area", [myVar1, myVar2])
with out: connect("area_enter", self, "_on_object_enters_area")

but you need to make room for them in your function that gets triggered:

func signalTriggerThis(area, myVar1, myVar2):
by (543 points)
selected by
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 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 webmaster@godotengine.org with your username.