Optimizing problems with my bullets! [UPBGE]

When my machine firing, fps was decreasing pretty much. I finally found the problem. Problem was the bullets thats comes from rifle. Anything doesn’t effect the fps but the bullets. How can restore my fps when my rifle is firing?

MY BULLETS:
-has no shadows,
-has backface culling,
-spawning up to number 10,
-are very low poly and has collision bounds,
-are dying after firing within 50 blender time unit.
-are rigid body but even if it has “no collision” feature, problem still occurs.

*My fps is decreasing only during the firing. After firing, there is no problem. Please help!

90% of the time bullet collision calculations are made using raycasts for optimal performance. Not with physical objects (that method will always prove to be physics heavy).

KX_GameObject.rayCast()

Documentation:
https://upbge.org/#/documentation/docs/latest/api/bge.types.KX_GameObject.html#bge.types.KX_GameObject.rayCast
Normally this would help performance enough back in legacy versions, but UPBGE 0.3x doesn’t have all of those performance optimizations unfortunately.


  • I see the major factor that is decreasing your framerate is your graphics column. You might try redeasing your sample count and game resolution if you haven’t already.

  • You might also look into your computer’s graphic settings and see if you could restrict some of the graphic effects. You’d be surprised how disabling some graphics settings that seem unrelated to Blender Game Engine really do effect it, performance wise.

1 Like

Is it perhaps related to the “addobject” process?
On my Windows PC I get a fps hit when adding objects and this also disturbs all physics calculations.

3 Likes

Yeah use a bullet pool if you must use objects.

Using raycasting / moving a moving a particle with geonodes per raycast is a good idea to ge the best of both worlds.

Each Frame if the raycast misses move up the ray

1 Like

wats physics type bullet you use? im use for object bullet sensor physics type for detect static colliders and spawn more 100 bullet in game and my fps equal 60 frame or use ray cast method -
start = barrel.worldPosition
end = barrel.worldPosition + barrel.getAxisVect([0, -100, 0]) # minus Y direction shot
ray = barrel.rayCast(end, start, 0, “”, face=1, xray=0)
hit = ray[0]
pos = ray[1]
if hit:
if “health” in hit:
hit[‘health’] -= 1
elif not “health” in hit:
bullet_hole = scene.addObject(“bullet_hole”, barrel, 0)
vect = bullet_hole.getVectTo(pos)
bullet_hole.worldPosition = pos
bullet_hole.alignAxisToVect(-vect[2], 2, 1.000)

1 Like

bullet_Pool_3x.blend (881.9 KB)

here is a bullet pool and ray marcher

it still needs a bit more polish*

edit:
polished :smiley:
bullet_Pool_3x_revision_2.blend (891.3 KB)

1 Like

I’m pretty much sure the question is about the ejected cases not the bullets shots. I’m going to agree with musikai and say it’s probably an issue related to ‘addObject’.

1 Like

bullet_Pool_3x_revision_3.blend (927.5 KB)

we can pool shell casings also, and not add them each frame, instead reusing them when we get back to bullet 120 etc

1 Like

bullet_Pool_3x_revision_4.blend (1019.0 KB)

edit:
final working -


bullet_Pool_3x_revision_5.blend (1.0 MB)

1 Like

Blockquote * You might also look into your computer’s graphic settings and see if you could restrict some of the graphic effects. You’d be surprised how disabling some graphics settings that seem unrelated to Blender Game Engine really do effect it, performance wise.

Can you tell me someting particular, for example?

Exactly. It is related “addobject” thing. When i typed -skip 20- in left button sensor that goes to “add object”, my fps increased a little more. But now, my bullet case production went way more down. Is it possible to keep high fps without not losing the amount of bullet cases?

Sounds great, but can you please send me an example file that shows ray cast method. I don’t know where i should put these codes into.

example_bullet_ray.blend (103.2 KB)
this example file (version UPBGE 0.2.5) press left mouse button and you see how substract health property and add blood mesh, in last block i create laser ray - for understand how work ray cast

Yes. Exactly problem occurs from addObject. But what is the solution of getting bunch of bullet cases without losing fps?

If you have a NVIDIA graphics card, go into your NVIDIA Control Panel and set all performance settings to maximum performance, literally and metaphorically.

  • Adjust Image Settings with Preview

    Slide the Use my preference emphasizing slider all the way to the left to state you prefer maximum performance

  • Manage 3D Settings

    Having the performance slider set to performance priority automatically disable most of these graphic settings, but if you’d prefer to, “keep,” some graphic settings enabled, you can re-toggle them here.

  • Set PhysX configuration

    If you have a dedicated GPU, you should be able to enable PhysX for that GPU. This setting can genuinely change your physics performance in a positive sense, quite drastically usually.

With lower screen resolution, this is what I can get in UPBGE 0.3+ in a default scene:

And you can too, if you have a strong enough computer and have set it to optimize its strengths.

1 Like

create flash muzzle shot - and assign this object to gun barrel - shot only ray cast, and make flash muzzle shot - visible or invisible - this imitation add to scene flash or bullet shot effects

1 Like