Connect function in code not working

Godot Version

Godot 4.2.1


I am trying to connect a signal to a function. I pretty sure that all the variables are properly referenced(since they are exported, and I set them to the node). I have gotten over this by connecting it in the editor, but I still want to make sure what I got wrong, because I know I can’t always connect it in editor. Here’s the code:

extends Node2D
class_name DeathHandler2D
@export var node_to_kill:PhysicsBody2D
@export var hitbox:Hitbox2D
@export var animation_player:AnimationPlayer
@export var my_collision_shape:CollisionPolygon2D:
		if not my_collision_polygon:
@export var my_collision_polygon:CollisionPolygon2D:
		if not my_collision_shape:
# Called when the node enters the scene tree for the first time.
func ready():
	if not hitbox.area_entered.is_connected(check_area):
func check_area(area:Area2D):
	if area is KillBox2D:
		if area.get_damage():
			var damage:int=area.get_damage()
func hurt(damage:int=0):
	if node_to_kill.has_method(&"hurt"):
	if can_one_shot(node_to_kill,damage):
		if node_to_kill.has_method(&"die"):

I know it is not any other problem, especially because the only thing that solved this problem was the connecting in editor.

Try somthing like this


Also make sure hitbox has monitoring enabled.

I have tried that way before too. Doesn’t work.

Can you use “body_entered” instead?

	$Area2D.connect("body_entered", (func(body):

No, I’m using an custom class that inherits from area2ds

I don’t think there’s enough information to solve the problem. Have you tried using breakpoints to see if the line connecting the signal is executed at all, and how exactly do you know the signal isn’t connected?

1 Like

I tried this, and the ready function just seems to not be calling, so I guess its a entirely different error now

I put it in enter_tree and it works now. Why?
EDIT: I just realized I misspelled ready. OMG I’m stupid as h*ck.

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