Topic was automatically imported from the old Question2Answer platform.
Asked By
rustyStriker
Old Version
Published before Godot 3 was released.
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)
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
Zylann | 2016-08-31 12:41
Well how do i get the object reference from the signal to the function to do code stuff with it?
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.
example:
func signalTriggerThis(area):
area.queue_free()
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: