Hi All,
I have recently gone on a hunt refactoring my code to get rid of all the stray nodes it was creating. There is one instance that keeps popping up in print_stray_nodes()
that I can't get rid of, however. It is the "explode" effect on my player projectile. It does not become stray every time I instance a projectile, only after several minutes of run time. Here is the code for the projectile. I instance the explosion tscn in the delete_missile()
function.
onready var explosiontcsn = load("res://Effects/Player_MissileExplode.tscn")
var toggle = true
var alive = true
func _physics_process(delta):
if alive:
self.global_position += velocity.rotated(rotation) * SPEED * delta
elif !alive:
delete_missile()
func _on_Area2D_area_entered(_area):
alive = false
func _on_VisibilityNotifier2D_screen_exited():
alive = false
func delete_missile():
if toggle:
toggle = false
trail.destroy()
self.remove_child(trail)
get_parent().add_child(trail)
var explosion = explosiontcsn.instance()
get_parent().add_child(explosion)
explosion.global_position = global_position
trail.global_position = global_position
explosion.rotate(rotation)
if Globals.missile_counter > 0:
Globals.missile_counter -= 1
queue_free()
Any ideas on what I can do to fix this to prevent the explode scene from becoming a stray? I spawn these projectiles pretty often as you can imagine, and pretty rapidly often. Thanks in advance.
EDIT: I just realized it is happening consistently at 22 seconds of runtime whether instance a missile or not????