How to optimize a game with many scenes?

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

So I have a simple 2D game that procedurally generates its maps. As of right now I only have a very basic terrain and trees generation.

Now, each one of these trees are created as scenes. This way the player can interact with them and it allows me to customize them more easily.
The thing is, with the world size I want (1024 by 1024 tiles), there are quite a lot of trees per world. Think thousands of individuals scenes (probably even tens of thousands).
This creates a lot of lag. Making the trees tiles allows the game to run at 60FPS, but with the way I’m doing it, it runs at around 24FPS.

How do I optimize my game to make it smoother? My guess is to only load the objects that are around the player, but I am not sure how to do that.
Also, I want to keep them as scenes if possible.

Thank you for that!

_NotH | 2022-08-07 20:01