Debuff implementation

Godot Version

v4.6.1

Question

really specific question. i have a debuff manager component and debuffs. the debuffs are added as children of the debuff manager. however, they do not seem to be queue_free()ing properly?

here is my code for each debuff:

extends Node2D

@export var damage : float
@export var duration : float

@export var slows_player : bool

@onready var stop_timer := $timer
@onready var particle_timer := $timer

func _ready() -> void:
	# despawn?? timer
	stop_timer.wait_time = duration
	particle_timer.wait_time = duration * 0.8
	
	stop_timer.start()
	particle_timer.start()

func _on_timer_timeout() -> void:
	queue_free()


func _on_particle_timer_timeout() -> void:
	$particles.emitting = false

here is my debuff manager code (probably really spaghetti’d because ive just been trying random stuff to fix this)

extends Node2D

@export var health_manager : Node2D

var damage = 0.0
var slow_player : bool = false


func recalculate_debuffs() -> void:
	damage = 0.0
	slow_player = false
	
	for child in get_children():
		if child.is_in_group("Debuff"):
			damage += child.damage
			if child.slows_player:
				slow_player = true


func _on_child_entered_tree(node: Node) -> void:
	if node.scene_file_path != "":
		for child in get_children():
			if child != node and child.scene_file_path == node.scene_file_path:
				node.queue_free()
				
				child.stop_timer.stop()
				child.stop_timer.wait_time = child.duration
				child.stop_timer.start()
				
				return
	
	recalculate_debuffs()

func _on_child_exiting_tree(_node: Node) -> void:
	recalculate_debuffs()


func _on_timer_timeout() -> void:
	# apply debuff affects
	health_manager.health -= damage

i have tried putting a print in the debuff thign where queue_free() happens, and it worked. whenever i print children of the manager in recalculate_debuffs(), the debuff is still there even though the particles stopped a while before that (definitely more time than would be left with the 0.2x difference between particles stopping and the debuff queue_free()ing)

sorry about this being really long. its a really specific problem.. i think? idk ive been trying to fix it for a few hours

You are using the same timer twice.

Suspect that’s why only one of your signal handlers is being called.

1 Like

dont know how i missed that lmao
i added that after the problem started though and it still doesnt work after fixing that

looking now, the debuff manager doesnt contain the debuffs still (dont know why that changed at some point) but the effects of them still remain

Likely because nothing is turning the debuffs off.

When does slow_player get set back to false?

1 Like

nevermind, figured something out that works. in _on_child_exiting_tree i did call_deferred(“recalculate_debuffs”). only sort of understand why that works (was just trying stuff and hoping) but it works

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