Error The signal "dead" is declared but never explicitly used in the class

Godot Version

4.3

Question

I got script Health_component which I use a lot (in player, in enemy, some breakable items), but i have that error. IDK why, cause i connect that signal to the characters.

Blockquoteextends Node
class_name HealthComponent

signal dead(killer)
signal damaged(damager)

@export var max_health: float

var current_health
var last_damager: Node = null
var is_dead: bool = false

func _ready():
if(max_health == 0):
printerr(“Did not set health for”+ owner.name)
return
current_health = max_health

func damage(damage_amount: float, killer: Node = null):
if is_dead:
return

current_health = maxf(0.0, current_health - damage_amount)
last_damager = killer

emit_signal("damaged", killer)
if (current_health == 0):
	is_dead = true
	emit_signal("dead", killer)
	printt("Dead signal emitted by", owner.name)
else:
	printt("Damage taken:", damage_amount, "Current health:", current_health, "Damager:", killer.name)

Blockquote

and enemy which should use it

extends CharacterBody2D
class_name clown

@onready var hitbox_component = $Hitbox_component as Hitbox_component
@onready var attack_component = $Attack_component as Attack_component
@onready var health_component = $Health_Component as HealthComponent
@onready var animation_player = $AnimationPlayer
@onready var sprite_front = $SpriteUP # Подключите ваш спрайт сюда

var speed = 50
var lastDirection = Vector2.ZERO

func _ready():
add_to_group(“Enemy”)
health_component.connect(“dead”, Callable(self, “on_dead”))
health_component.connect(“damaged”, Callable(self, “on_damaged”))

func dead(_killer):
hitbox_component.disable_hitbox()
print(“Enemy is dead”)

func on_dead(killer):
if killer !=null:
print(“Enemy is dead, killed by:”, killer.name)
else:
print(“Enemy is dead”)
play_death_animation(null)

func on_damaged(damager):
if damager !=null:
print(“Enemy took damage from:”, damager.name)
else:
print (“Enemy took damage”)

why i got it?

4.0 prefers to use signals directly instead of by strings. Try

dead.emit(killer)
# instead of: emit_signal("dead", killer)

When pasting scripts make sure to use three ticks to define a code block like so

```gd
type or paste code here
```

1 Like

Thx!!!

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