Error calling from signal 'area_entered' to callable:

Godot Version

<stable4.2>

Question

<hurtbox class works perfectly fine and enemies takes damage whenever collided with hitbox. However, the console prints an error Error calling from signal 'area_entered' to callable: 'Area2D(HurtBox.gd)::_on_area_entered': Cannot convert argument 1 from Object to Object

@icon("res://Entities/node/HurtBox.svg")
class_name HurtBox
extends Area2D

func _ready() -> void:
	connect("area_entered", Callable(self, "_on_area_entered"))

func _on_area_entered(hitbox: HitBox) -> void:
	if owner.has_method("take_damage") and hitbox.is_in_group("bullet"):
		owner.take_damage(hitbox.bullet_damage()) #Enemy Take Damage By Bullet
2 Likes

connect(“area_entered”, _on_area_entered)

still receiving same error

i believe it’s because forum’s double apostrophe is messed
try copy and paste this again

connect("area_entered", _on_area_entered)

nothing changed. still getting same error

what the error said

you dont need to specify this type, just do

func _on_area_entered(hitbox) → void:

I thought i needed to specify the type, since without that, i got an error Nonexistent function 'bullet_damage' in base 'Area2D'

change to

owner.take_damage(hitbox.bullet_damage)

I get an error Invalid type in function 'take_damage' in base 'CharacterBody2D(enemy.gd)'. Cannot convert argument 1 from Callable to int.

your bullet_damage is int or there’s no type to it or actually a function?
just do it like this:

owner.take_damage(int(hitbox.bullet_damage))

if this got an error again, post your full code of bullet damage and even take damage code

@icon("res://Entities/node/HitBox.svg")
class_name HitBox
extends Area2D

@export var damage := 10
@export_range(0, 1) var crit_chance: float = 0.2

func _ready():
	randomize()

func bullet_damage() -> int:
	if damage == 0:
		return 0
	else:
		var crit_multiplier = crit(crit_chance)
		var random_multiplier = 1.0
		if crit_multiplier == 2.0:
			random_multiplier = randomness()
		var final_damage = damage * crit_multiplier * random_multiplier
		return int(max(final_damage, damage))
func take_damage(amount: int) -> void:
	print("take damage")
	print("DMG:", amount)
	health = max(0, health - amount)
	if health == 0:
		state = States.DEATH
	var tween = create_tween()
	tween.tween_property($AnimatedSprite2D.get_material(),"shader_parameter/flash_modifier", 1, 0.1)
	tween.tween_property($AnimatedSprite2D.get_material(),"shader_parameter/flash_modifier", 0, 0.1)
func _on_area_entered(hitbox: HitBox) -> void:

I believe it doesn’t like the type specified, it cannot convert every object that enters the area from Area2D to HitBox. Best to use an if statement to deduce the extended types

func _on_area_entered(hitbox: Area2D) -> void:
	if hitbox is HitBox:
		if owner.has_method("take_damage") and hitbox.is_in_group("bullet"):
			owner.take_damage(hitbox.bullet_damage()) #Enemy Take Damage By Bullet
1 Like

problem solved! Thank you so much!

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