Queue_free() dont work

Godot Version

4.2 Mono

Question

There is an arrow prefab, when fired it creates a new exemplpyre and flies towards the mouse. The logic of the arrow is simple: Hit - Caused damage to the enemy, then removed itself. Out of the screen - removed.
However, instead of deleting, the arrow simply “freezes behind the screen” and when I approach it, it “comes back to life”. That is, the arrow flies while I look at it, otherwise it “freezes”.

arrow script:

public override void _PhysicsProcess(double delta)
        {
            if (attackComponent.HasOverlappingAreas())
            {
                attackComponent.EmitSignal(AttackComponent.SignalName.Attack, projectileResource.attackResource);
                this.QueueFree();
            }
            if (!visibleOnScreenEnabler2D.IsOnScreen())
            {
                this.QueueFree();
            }
            movementComponent.Move(this);
        }

movement script:

public void Move(Projectile projectile)
        {
            projectile.GlobalPosition += Speed * Direction * Convert.ToSingle(GetPhysicsProcessDeltaTime());
        }

QueueFree() is used by everyone, myself included. have you verified it is actually being called? try adding GD.Print(“attackComponent.HasOverlappingAreas”) and GD.Print(“visibleOnScreenEnabler2D.IsOnScreen”) before your QueueFree() calls. also try printing the name of the node you QueueFree().

I put this in:
GD.Print(visibleOnScreenEnabler2D.IsOnScreen());
Anyway, this node doesn’t work because it always writes that the object is on screen. I don’t remember what shenanigans I did long ago to make it work

You need to use a VisibleOnScreenNotifier2D not a VisibleOnScreenEnabler2D as it will disable processing of the ode when exiting the screen and won’t reach the check to queue_free() the node.

Yeah, that’s right. When I was looking at an old project, I didn’t pay attention to that one word in the node name…

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