Do i need to destroy objects that have passed the screen / or those that simply died, to save recources?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nickster076

If that is a good idea, how would i tackle this?

The idea is an enemy dies the hitbox disappears, but the hitbox isnt really a hitbox but an Area2D on a Node. (no Collisions but its for triggered animations.)
I tried disabling visibility with signals but i cant get it working.
set_process(false) or .show() .hide() also no luck.
I’m not sure wether to attach it on my enemy scene or the world scene.

:bust_in_silhouette: Reply From: Merlin1846

When your enemy dies have do everything its supposed to do when it dies then call queue_free()

What queue_free() does is it deletes the node and all its children from the scene tree.

So if theres this set up in the tree.

-node2D
–enemy manager
—enemy1
----sprite2D
—enemy2
----sprite2D
–other stuff
–other stuff
–other stuff
–other stuff

and queue_free() is called on enemy1 then this is what it will look like.

-node2D
–enemy manager
—enemy2
----sprite2D
–other stuff
–other stuff
–other stuff
–other stuff

Now I don’t beleave that turning off visibility on nodes actually disables them, but I do know that it doesn’t save resources very well because the nodes are still there taking up resources. While queue_free() completely deletes the node from the scene tree.

Now depending on what kind of game you have you might not want to queue_free() nodes that have left the screen if the player is able to move the camera and go look for them. But if your camera cant move and is always focused on the same spot then maybe. Its really up to you.

You’re a legend, added it to a signal and that was all was missing.
You’re right about camera stuff, so i just apply it on enemy after death animation is done.
So lets imagine i want to bring it back to i type something like get.tree?
Sweet, Thanks!

Nickster076 | 2020-05-03 16:13