diff --git a/objects/player/arrow_projectile.gd b/objects/player/arrow_projectile.gd index e4bedf3..a3964a9 100644 --- a/objects/player/arrow_projectile.gd +++ b/objects/player/arrow_projectile.gd @@ -59,22 +59,24 @@ func _on_Hitbox_area_entered(area): queue_free() func _persist_trail(): - var particles = $DustParticles - remove_child(particles) - get_parent().add_child(particles) - particles.global_position = global_position - particles.emitting = false - get_tree().create_timer(particles.lifetime, false).connect("timeout", particles, "queue_free") + # don't do this twice to prevent crash + if not is_queued_for_deletion(): + # make particles a sibling so it lives a bit longer than arrow + var particles = $DustParticles + remove_child(particles) + get_parent().add_child(particles) + particles.global_position = global_position + particles.emitting = false + # free particles once they have gone through their lifetime + get_tree().create_timer(particles.lifetime, false).connect("timeout", particles, "queue_free") func _make_sparks(): - # return if this has already happened to avoid crash - if is_queued_for_deletion(): - return - - var particles = $SparkParticles - remove_child(particles) - particles.global_position = global_position + particles.position * scale.x - particles.emitting = true - get_parent().add_child(particles) - var timer = get_tree().create_timer(particles.lifetime, false) - timer.connect("timeout", particles, "queue_free") + # don't do this twice to prevent crash + if not is_queued_for_deletion(): + var particles = $SparkParticles + remove_child(particles) + particles.global_position = global_position + particles.position * scale.x + particles.emitting = true + get_parent().add_child(particles) + var timer = get_tree().create_timer(particles.lifetime, false) + timer.connect("timeout", particles, "queue_free")