UPBGE batching


I’l would like use batching to optimize my game but, i have try to use some exeple i’ve find, but it doenst work very well.

i have try batch_test.blend file exemple we can find on this forum, but when i try to change by my 3D model it doenst work, and tell me an message “no model to merged”, i have see if i replace my name model by an number is work, so i dont understand.

Someone can shae an blend file exemple work, or script to explain because im blocked.

I’m would like have like that

from bge import *from mathutils import *

scene = logic.getCurrentScene()
own = logic.getCurrentController().owner
batch = types.KX_BatchGroup ([obj for obj in scene.objects if obj.name[0] == “colune4”])

find all model have name colune4 like that colune4, colune4.001, colune4.002 and more and after can possible to batch other models like stair1, stair1.001, stair1.002

Otherwise i’m would like to know if batching work with group name, because it’s not explain, exemply like for assets map called into main blend file, and use name group as name object.

i have try but i have everytime an error.

Thank you.

object.name[0] == “colune4” means object which name’s FIRST CHARACTER equals “colune4”. Surely you can understand that the condition will really never return true, hence why the list of meshes passed to the batch function turns out to be empty.

So how i’m suggest to do, have you an exemple?

You are creating a list on the go with this bit of code (taken from what you already have):

[obj for obj in scene.objects if obj.name[0] == "colune4"]

The filtering happens in the condition, so far you wrote:

if obj.name[0] == "colune4"

But if I try any name, here is what happen…
Lets take an object named “Cube”. We have obj.name = “Cube” at some point in the loop.
obj.name[0] is the first character, here it would be “C”.
The test is the same as “C” == “colune4”.

This will never work.

Just find a condition that better suits your need. Look for Python conditions if you have trouble, and string comparison.
I mean just write something that makes sense and suits your needs.

edit: tu peux faire un tour sur OpenClassroom (anciennement site du zéro) pour de l’aide sur Python etc… Le principal problème dans ton code c’est que quand tu essayes de générer une liste d’objets à batcher, ben à cause de ta condition ya rien quoi.

Also if they are all the same mesh just click use geometry instancing*

does that actually work? I was told otherwise, but I should test it myself.

I have try geometry instancing, but it’s an shit, and not work with model have more than 150 polygon, so until, and FPS get less.

Otherwise for the python condition i have find that:

[obj for obj in scene.objects if “colune4” in obj] i think it’s work but not sure.

i have made an batching test i share the blend file, it’s work for me with no error and support too many object and polygon.

i dont know how is work and why but if i use obj.name.startswith it’s work fine with no error.


Let me konw if for you is work, the scene have 800k polygon test.

Batching doesnt support object are linked from other blend file, but append object work with my script, i have try to add group of differents assets and is work too if you call the name of the model and not the name of the group.

exemple for multiple object in same line

from bge import *

scene = logic.getCurrentScene()

types.KX_BatchGroup ([obj for obj in scene.objects if obj.name.startswith(“Cube”) or obj.name.startswith(“Suzanne”) or obj.name.startswith(“Icosphere”)])

other test on real asset, 800k poygon too with 4 texture 2048x2048, you can look difference, but i find not crazy the optimization with batching, 135fps between 115fps without…

not sure batching have an real interet finally if its just 10 or 15 fps, i’ve expect more like 30fps.

Batching works, but it just joins meshes in game. Its good because it allows you to merge and split in game the objects. But its the same as joining object. Its best to use the feature if you have multiple of objects with a single or so material, like in a shelve. I think you have to add the - bge.types.KX_BatchGroup to make it work if i remember.

Yeah all obj using batching need to use a material atlas,

All building etc are made of pieces of geometry using the same pieces 100s of times.

This is what batching is best for.

This is how I assumed batching worked myself…in my tests I find it better to just join the objects myself outside of the game engine…it gives slightly better performance…this is how I am trying to manage my trees atm. I am currently sitting at 57-60 FPS by joining them by hand…when I use batching I get 55-58 FPS, I’m not really certain why…but it is what it is…I am sure there is a much better way to do what I am trying to do…but I’m an idiot(and proud of it!) I make no excuses :slight_smile:

I have try different method, first method to have the best fps is calling assets from an other blend file with link, but that method not allow batching^^, otherwise with batching i have the same result of you, but i have see like the screen i have share, you can see my container model have more fps with batching, but if i put others assets on map and make the same method i have less fps with batching activated, so yes i think batching it’s just an shit system because if we look on UE4 batching system, we win a lot of fps, for my part i will add the batching but not sure can give to user the best after i have RX vega64, so for me the diffrence is little, maybe on small configuration can be more interesting, anyway for real game like i want i’m cant use texture atlas because can reduce my quality texture.

It’s cool to see some others guys have same problem of me, otherwise the file i have share about batching is the good solution, that method count all model have the same name, i think it’s the best way and simple :slight_smile:

About geometry isntancing, i have see when i active it on any model i receive in console an totblok error 1, so maybe the sytem too is bugg, if someone can verify too, anyway 150 polygone for using is really funny, need like 1000 poly not 150…

geometry instancing on a set low poly ‘trims’ you use 1000s of times works great.
(all trims use 1 atlas)

this ends up being like 1 draw call for each trim geometry type

(where all objects use 1 large material atlas)
can batch all objects that share material into 1 call.