Noticeable micro freezes using scene.addObject

In Upbge 0.3, the ship can fire projectile, each time there is micro freezes, very noticeable playing in viewport mode (instead of fullscreen) whith camera looking aside space ship (instead of behind); it’s not great at all as a game should be smooth :

scene.addObject(“projectile1”,firePosition,100)

How can i activate and deactivate some object visibilty and physics on code ?
(I think making a pooling system)

Also i have a strange bug in viewport mode launching the game, sometimes emission material on projectiles deos not activate, soptting and launching the game again the emission material works; and so on.

Are you sure it’s on every shot, or just the first? In regular BGE, I find there is a noticable delay on the first added object of its type.

If so, you could add all of your objects at the start behind a loading screen to get the initial lag out of the way.

At atsrta veything new objects are loading, so during some time it’s not smooth, but once the game is running from some time, i can notice the mirco freeze.

Using the addObject function in Python is slower, since Python is a interpreted language.
C++ on the other hand, is not an interpreted language, so it’s faster.
Logic Bricks are made with C++, so I recommend using the Edit Object (Add Object) actuator instead of using the Python function.

1 Like

addObject with python, bricks, or c+ is all the same, none is faster then the other.

However if you add like a few 100 every tic then indeed c++/brick is fastest, but then again python is still the best, because you have complete control over it. Right after spawning adding properties, clothing, changing position/orientation, or whatever is best done(if not only possible) with python. so the speed gain is actually non existent.

Using logic bricks while you can use python is a strange thing for sure. For 1 object sure but for a few 100 objects that adds like 1 or 2 things, bricks ain’t the way to go, unless you really really like spaghetti.

You have micro stutters, check if:

  • mesh is low poly
  • textures aren’t 16k
  • don’t have lots of noise in them
  • adding only 1 object and not like 50 in the same time.
  • using libload? check if your h.d.d/ssd is not working at 100%(or in sleep mode)

and NEVER use embedded player, but the stand alone, if you don’t have stutters in stand alone then everything is fine.

2 Likes

I would expect something written with this much confidence to actually be correct and I believe this is far from it. I challenge you to show me a blend where you can demonstrate that adding the same object with the actuator is faster than doing it through Python.

And before you start on it, you can skip talking about metrics showing that Python being slower than C++. I’m looking for proof that the casual observer can see it takes longer to add an object via a Python call. I.e. helping with the actual problem that OP is asking about.

i have noticed the same problem and it happens at every new object added.

proejctile

Try the demo, paly in this view ( don’t press “0” camera view )

Start the game
Continuously moving with A and Q and.
Wait some time for game to become smooth
Then keep moving , while keep “SPACE” pressed to fire projectiles

testaddobject

Hmm, looked at it and i don’t see any stutter, with or without holding space down it’s the same.

Then there is something else to fix, like a bug in UPBGE, a driver update, or something else going on at the same time. But whatever it is, it’s not because Python is slower than C++. The idea that you should stick to logic bricks over Python at all opportunities is patently insane. If Python is fast enough for EVE Online to use for its servers, then it’s fast enough for BGE.

For the record, I have never had any microstutters (after the first time an object is loaded) while adding objects via Python in BGE.

I don’t have a version of UPBGE at my disposal at the moment so I can’t try this for myself… but it might be worth swapping your projectile for something basic (without the glow) and see if you still get the problem. It wouldn’t surprise me if the pretty graphics cause some graphics cards to hiccup.

1 Like

why are droning on about c++ vs python and logic bricks ??, i never said anything about that!.
i am also using python to add in objects.

1 Like

…because you replied to my post which was talking about it, while adding that you also have the same problem?

Perhaps you should take more care with your posts in future. The way your original reply reads at the moment is that you also get micro freezes by adding objects via Python vs via logic bricks.

nope the post above it.

the more objects in the scene, the more it costs to add object I assume O(N) stuff with inserting the object into the running scene

probably more noticable on something already taxed out

1 Like

Yes, more noticeable also running in 4K while the scene is very small and very low poly.
Perhaps Upbge 0.3 will need low level draw mesh and objects instance performance improvments later or do some things on GPU instead of CPU.
But this is ok for the game demo template, it’s playable.

you could use a bullet que

this is what I did when add object had issues a while back (flickering etc)

I think it’s about Windows Cpu and App allocation, or some Cpu and memory leaks i don’t konw. But it’s more about OS and allocation.

There was another app windows popup when Upbge was running in game mode, and everything was like slow down.
For example the player firing lot of projectiles, sometimes all addObject events slows down and sometimes those speed up again.
When i restart Upbge everything is super fast about addObject.

What is strange is Upbge always displays 60 fps ? but some Upbge systems runs more slowly, are they multi threaded so not really took account in the fps counter or it is the code ?

    timeD = time.process_time()-  owner["timeFire"]
    if timeD > owner["delayFire"] :  
        owner["timeFire"] = time.process_time()
        print("FIRE")
        firePosition = scene.objects["fire"]
        scene.addObject("projectile1",firePosition,50)

I was wondering if you tried setting up the Logic Tree Nodal System. So far it easy to add the cube move by pressing just the 4 key movement button. However, the addObject or Edit/ADD Object Logic Bricks is not replicated in the Logic Tree System. In addition, the CUBE Move does appear to be mathematical possible because a object at rest (0) times the 1.5 still equal zero. This nodal setup is different from Armory3d Blender Nodes. The applied movement, applied classes and applied…work some what… https://www.youtube.com/watch?v=QjWr77wFwv0