Instantiate() a new object when it queu_free()

Godot Version

Godot 4


so I have been trying to make pong for an embarrassing long time now, but got stuck trying to instantiate the ball back when it goes off screen and queu_free().
I got an @export PackedScene of the ball in the main scene script, and a VisibleOnScreenEnabler2D with a signal in the ball script.
I think I need to add a Timer node with a signal to make it happen.
Screenshot 2024-04-02 112459

here’s what’s got added in the scripts

main scene:
Screenshot 2024-04-03 085116

pingpong ball scene:
Screenshot 2024-04-03 085101

after instantiating you need to add it to your scene
try :

I did it did nothing.
Screenshot 2024-04-03 100229

you didn’t call it yet

you should specify your code, scene, and your problem more.

I kind of solved it but it’s not spawning on a timer now.

what I wrote and change:
Screenshot 2024-04-05 123508

In the enabler signal receiver, have the script start a timer that is NOT a child of the ball that will be queue_free()ed, then queue_free() the ball. Then, in another script, when the timer goes off, spawn a new ball. That should work.

P.S. It would be helpful if we had a screenshot of your node list on the left.

1 Like