How to fix error cannot convert argument 1 from object to object

Godot Version

4.6

Question

Hello i was trying to make a projectile deal damage on my game by connecting the signal body entered to a function called Hit

But whenever a body entered the hitbox area i would get a error. Hit function:

I dont know why. My class hurtbox component extends from area2d so i dont know why its not working

Here is my hurtbox component code too

If you’re declaring the type of the argument in the signal handling function it must match the type that’s specified in the reference for that signal. In the case of body_entered it’s Node2D. Either that or don’t declare the type at all.

You also have serious capitalization issues that if they’re not now, are going to burn you down the road. In your signal, you send Body: HurtBoxBody and in your function you look for argument body: HurtBoxBody.

Then, as @normalized points out, you’re sending a variable of type BaseSpell.

I think your actual problem is your spell is triggering the Area2D, and you assume only a HurtBoxBody can enter it. So either change the physics layer the spell is on and detect it some other way, or pass Node2D as @normalized suggested, and then have your code deal with the different objects coming in.

I also recommend you follow the GDScript Style Guide and make your variables snake_case. Otherwise you’re going to start having naming conflicts.

I managed to fix the error and i am rewriting code to make it better. Thank you guys for the help

Not a problem but i will write anyways since someone might run into this problem in the future

I tried connecting the body entered signal to a function but the body entered would never fire since my hurtbox is an area2d not a body like CharacterBody2D.

1 Like