I have a bullet hell game wherein hundreds of projectiles(area2D that I move manually by changing its position per frame) might be active at any point, and maybe twenty or thirty will be deleted (and spawn short-term particle systems) per few tenths of seconds.
Is this sustainable, especially if I’m considering adding lights to each projectile?
Are there any weird behaviors? Will the Node Name be so long that Godot just crashes? (i.e @Area2D@37812718923869 or similar taking up more space than Godot has set aside for the name property)
This should be possible, but you might want to consider pooling the objects. Dont queue_free them when they are done, instead remove them from the scene tree and reuse them later
Adding and Removing nodes is one of the most taxing operations in godot, avoid doing it per-frame in general, let alone 1000 times per-frame.
Here’s a old video on exactly what you are trying to do, object pooling will be your first task. instead of queue_free, hide and set_process(false). instead of .instantiate(), show and set_process(true)
Yes object pooling. You can remove them by calling “remove_child(node_to_remove)” on the parent or just use hide() and set_process(false) as gertkeno suggested. Make sure to save them in an array or something to prevent memory loss
Is it best to make the pool of objects in _ready() or do it in the editor? I have 50-ish shooter objects and I reckon each will need 4 or 5 projectiles pooled.
I think there is no reason to do that manually. Actually, it’ll still be instantiated by the engine when the game is launched.
However, you’ll only get at most 300 projectiles instantiated as you described. I think Godot can handle that since the implementation is highly optimized with C++, rather than the crazy garbage collector in C#.
The difference is that queue_free deletes the object from memory while remove_child only removes it from the scenes tree, but it can be added to it again with add_child without instantiating again