Need help optimizing creating a lot of objects

Hello, this is my first forum post here, as I’m kind of a newbie to Gdevelop and couldn’t find this specific solution.
I’m making a survival game similar to Don’t Starve, where you gather resources and make stuff. At the beginning of the Game scene, it creates a few hundred objects of the many stones and trees in the world. This mass object creation creates a lot of lag. Is there any way I can make this more optimized to improve performance?

Do you also create the objects that are out of the screen borders?

1 Like

Yes, it creates all of the resources within a big area

Then you should only create those objects that are visible, you can use the ‘Destroy when outside of screen borders’ behaviour for this. It’s like render distance.

1 Like

Lag, as in the whole game just runs really slowly, or just a delay at the start of the scene?

If it’s just a delay, then present a progress bar with the caption along the lines of “Generating the world”. It happens to the best of games (like minecraft?).

Alrght, i did that, and it makes the game run pretty well but this creates a problem
lets say a tree spawns in radius of the camera (not outside the screen) and i move to where its ouside of the camera and it gets destroyed. I want it so that when i go back to where the tree was it was in the exact same place when it was there inside the screen.

Yes, why would it persist if it gets destroyed? If you implement Csongi’s suggestion, you’ll need to keep track of every object and create it when it gets near camera and screen. And that can get messy.

ive come up with a solution that i think works best.

Trees and Rocks will only generate in the cameras radius, and stay there in or out of the camera. Once you’ve gone out of that area, new trees and rocks start spawning and will stay.

1 Like