How to make upbge(bge) script to improve logic run time and increase framerate

I have been trying to make a larger world game in blender. I have a script that makes objects vanish if to far from player character and spawn if in range. When still the frame rate is about(60fps), but if you move logic rises and it drops to (12-2 fps). If you can help please do!

If you are having these problems that I was having try looking at these post they help me solve this problem.

https://blenderartists.org/t/how-to-do-threading-in-upbge-bge/1420451/11

https://blenderartists.org/t/how-to-add-objects-once-in-range-from-dictionary/1422979/37

1 Like

you need to understand that the open world is not built solely on one logic (and even more so not built on the same logic bricks) you need a system of chunks and not noticeable loading of the landscape based on elevation maps or procedural noise maps - perlin, Chebyshev, multifractal - you can’t build an open world too far from the center of the stage so as at very large distances, you will get the effect of not accurately calculating binary variables, which will lead to twitching and strong fluctuations both models and game cameras therefore, you need to organize the world of the game so as not to go far from the center of the scene - either loading new regions with a loading screen that will return the new landscape to zero coordinates and the player and reading regions (chunks do from the world map that is in another scene) You can also generate landscapes through - vertex keys and animation of these keys - but then you need to recalculate the physics of the mesh modified by such animation through terrain.recalculationPhysicMesh() after several iterations, since recalculating the physics of the mesh at the time of the game is quite a heavy operation And finally - a little advice to save your time - do not make games with a large, open world like Skyrim - the simplest reason is that you will have nothing to fill them with - you can generate whole planets, this is really what I did - but to make it look like an open world, you need heaps of objects - bushes, trees, houses, stones, characters - don’t be naive open-world games for studios

1 Like

Thank you @Villi89 for the advice. By logic I was not talking about bricks turns out one of the biggest problems I was having at the time was .AddObject(), and turning objects invisible was not helping either it raised the logic or GPU in the debug that is on the top left of the screen .I actually never played Skyrim. I was more going for breath of the wild mix with the old PS2 game hack so I started placing objects like flowers grass money then pressed play drops to 2~framerate …Oops. One thing I never had a clue of is Pooling objects instead of keep adding and deleting them. The landscaping is very interesting I was vaguely more aware of this concept than the other concept but I don’t know how to do that. Yes I watched the video and read what you said, but I’m a beginner I would not know how to make the stuff I would need for that much less program the system it would run on I found a post from a link in the video but all of the files on that post seem to be outdated. Is there anyway you could help me please?

are you using upbge 0.25 or 0.3 ?

  • how many lamps
  • how many vertex in the scene
  • screen resolution
  • how much animations running at same time, how much channels in each animations
  • many 2d filters, if yes, how many samples each
  • camera distance clipping
  • how much code running each time
  • how much % animations use in your debugging panel ?
  • some others

for all the scene, cheat as much as possible by using low poly or even sprites based on distances

I’m using UPBGE 3.0. I have one lamp, one armature and about 5000 cubes. When the game plays only 259 cubes are present. The ones in the pool. The framerate at present stays around 19 ~ 24. Most depsgraph seems to be consuming the rate with it at 59%.

if you use UPBGE 0.3.0 - for terrain generation use geometry nodes - this get for you procedural generated terrain how displacement mesh surface - 5000 cubes in a scene using physics for them creates too much load for physics - if you want to avoid this, you need to suspend the use of physics for objects at an average distance from the camera - this can be done through iteration of scene objects -
for i in scene.objects:
if own.getDistanceTo(i)>15.0 and “Phys” in i:
i.suspendPhysics()
elif own.getDistanceTo(i)<10.0 and “Phys” in i:
i.restorePhysics()
but I still think that there are a lot of 5000 cubes as units of objects - the game engine is easier to process a smaller number of objects, even if the number of their polygons will be like 5000 cubes - keep this in mind. I ran scenes in which there are about 14-15 million polygons, but it was distributed over several objects - floor, walls, roofs, mountains and other objects, but there were not many of them. I noticed an interesting moment - when I tried to assemble a scene from a thousand objects, it began to freeze for 2000-2500 objects - when I made these objects into single meshes for some one object, the freezing disappeared and I was able to add even more polygons and details. in your case, I think you need to make regions - an object of 5 x 5 kilometers a piece of land on which you create objects - one mesh for the floor, one mesh for the walls, one mesh for the roof or ceiling - the point is not to have many objects in the scene and use materials and textures for a specific object - I so I realized that the game engine does not handle a large number of objects well without cutting off the render and physics and still stores information about objects - their position, rotation and scale, which gives overload to the game

there have always been problems with the add object function - especially if the object is added for the first time during a game session, an easy way out in such a situation is to add a plane and replace the mesh and physics with it through the replace_mesh actuator - or do it through a script and iterate physics - in 0,3,0 UPBGE in geometry nodes it is possible to place objects on the mesh of the earth from collections - at a certain distance from the active camera - this will save you from having to add and remove objects

I don’t actually have 5000 cubes in game.when the game starts their locations are saved to a list then they are all deleted. Then about 52 are spawned at an empty called pooled to avoid have to use AddedObject() often later. Then the cubes with a world location in range will be called from the pool to spots close to the player and sent back to the pool for later use. So there are really only 56 cubes. The .physics suspend()
Is good advice, but right now it seems to make no difference my physics is at 0% along with logic and Animations. Only dephsgraph rasterizer and GPU latency are dropping
frame rate. I messed around a bit more I can get about a 50~framerate if my computer is on high performance.

I have no terrain system at all I don’t know how to make one the player just walks on a big plane I have no idea how to use geometry nodes to do that. I don’t even know how to use remesh().

This video help for you understand how work and how use geometry nodes, if you use this system you get for game procedural generation landscape objects in scene.
For rasterize off vsync - or stand vsync in adaptive mode, and use clipping distance for active camera in game and in end camera vision range create mist for close rough zone.
And search and look more video tutorials in YouTube

1 Like

Thanks. I will look into it.

I have put up some clips of my game so that people can see how it is at the current state

https://blenderartists.org/t/plant-girl-strawberry-sketchbooks/1440777/7