Help With Insantiated Area2D

Godot Version

4.6

Question

So, I’m very new to gdscript and I’ve been trying to make a global that can make hitboxes for me, but I cannot for the life of me able to figure out how to get the body_entered signal to work.

extends Node

signal create_hitbox()

func _ready() -> void:
	Signals.create_hitbox.connect(_create_hitbox)
	pass

func _create_hitbox(position : Vector2,scale : Vector2,damage : float,time : float):
	var hitbox = CollisionShape2D.new()
	var area = Area2D.new()
	get_tree().current_scene.add_child(area)
	area.add_child(hitbox)
	hitbox.scale = scale
	area.position = position
	area.monitoring = true
	if area.is_node_ready():
		area.body_entered.connect(_on_touched)
		pass
	else: 
		print("failed")
		pass
	await get_tree().create_timer(time).timeout
	area.queue_free()
	pass
	
func _on_touched(body, damage):
	print("test")
	pass

I assume you are just not showing the part where something else does a create_hitbox.emit()to actually trigger the signal? That is, you are sure your _create_hitbox function is actually running? Perhaps you can show the code that emits the signal?

But also, your signal create_hitbox doesn’t define any parameters, but your signal handler function _create_hitbox() does..