Procedurally adding objects

I just want to finish my game now, getting quite tired of it now :P, but having some performance issues, which I can’t seem to fix. Sometimes I have to add about 40 different objects, each ranging between 10-200 vertices in a single frame. My game is a sort of side scroller, where different parts of the level are added/removed as you progress through. The biggest problem is that, it starts to freeze briefly while this is occurring. I’ve added multi-threading but it only makes minimal improvements, maybe i’m doing something wrong idk. Is there another way to solve this problem?

Any help would be appreciated, thanks.

Thing is you are pushing a lot of data to the GPU in the moment you attach the geometry (meshes). Try not attaching all in one frame.

1 Like

If you can’t batch them into larger single objects then you might try just adding a few per frame if you can get away with it. Otherwise, you are probably spending lots of time dispatching new geometry to the GPU during a single frame. Each object has overhead far greater than its size… which is why fewer larger geometries are better than hundreds of little ones.

…but spreading the adding of little ones over a few frames can help. In Mythruna, I only add one new geometry per frame… but my geometries are quite large.

1 Like

not sure how to batch yet :P, so ill try adding them over a course of frames, thanks!

Try using renderManager.preload() on the parts of the level that you’re loading. This will upload the mesh data to the GPU so if you limit it to like 5 calls per frame while you’re loading the further parts of the level it will have less freezes.

1 Like

cheers for the help all, i couldn’t manage to get it to work right (it did improve), but the organization of my game made it hard to do right :P. I just decided to put the whole level in memory at the start, makes my life a lot easier :P, the frame rate is a lot worse now tho, drops to 80 fps now on the most intense levels, but still getting about 250-300fps on simpler levels, which is fine with me, i just hope android phones can handle it :O, im sure theres still improvements i can make in my code as well. Thanks again! these tips will help me a lot next time! now i know how to design a game properly from the start :smiley: <3 u all