Why doesn't connecting an Area2D signal work?

I have an area2d var in code i call like this

@export var EatBox : Area2D

I then do this to connect to the area entered signal in the _ready function

EatBox.area_entered.connect(_eatbox_entered)

Currently the _eatbox_entered function just is supposed to print something out in the console for testing, but for some reason it just doesn’t work, I have no idea why, it’s not an issue with the layers or mask that’s correct

Technically this isn’t “calling” the Area2D. It is creating it. In fact it is just creating a variable to hold an Area2D
As it sits, EatBox contains nothing. It is null.
When you @export a variable, you will then have to go into the inspector and fill that variable in.
However if it is empty (or rather null) then you should be getting an error on the connection line;
Invalid get index 'area_entered' (on base: 'Nil').
Are you getting any errors?

I want to also note that the area_entered signal will only fire when another Area2D enters. It will not fire when a body enters such as a CharacterBody2D.
For that you will need to use the body_entered signal.

Oh yeah no, I get how export variables work, I am putting something there which is why I’m confused, I’m not getting any errors it just doesn’t do it for some reason.
It is also checking for another area2d so it should be good there

Yeah I double checked everything, maybe it’s cause I’m trying to do in a state with a state machine or something

Does your _eatbox_entered() function match the Area2D entered signature ie does it have the proper parameter?
func _on_eatbox_entered(area: Area2D) -> void:

THIS WAS IT
Thank you so much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.