This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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:

func _on_Area2D_area_entered(_area):
    alive = false

func _on_VisibilityNotifier2D_screen_exited():
    alive = false

func delete_missile():
if toggle:
    toggle = false
    var explosion = explosiontcsn.instance()
    explosion.global_position = global_position
    trail.global_position = global_position
    if Globals.missile_counter > 0:
        Globals.missile_counter -= 1

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????

in Engine by (616 points)
reshown by

1 Answer

0 votes
Best answer

Is there anywhere else in your code where you change the value of "toggle"? Your deletemissile() function only deletes the node if toggle is true. I don't know how the rest of your project is structured, but if toggle gets set to false somehow in another part of the code, then queuefree() may never get called.

As an experiment, you could try removing the conditional statement and seeing if that fixes the issue. Would at least help you narrow down possible problems.

by (74 points)
selected by

Hey thanks for the reply,

I couldn't figure out how to delete the question but I figured it out. It was because I was doing var X = preload(explode_tscn).instance() in another unrelated scene! This was what originally set me on this stray node hunt because I did this on all of my scenes!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.