How can I script an object to explode via a modifier in Python? Is there such a modifier that is the reverse of the Build modifier that explodes or deconstructs an object?
Take the prefractured pieces and turn them all to rigid bodies and place them using 0,0,0 as the origin and group them, spawn the group instance when breaking the object.
Maybe as a suggestion, there could be a new modifier called “Fracture” added to newer versions of Blender and UPBGE.
there is a addon that does fracturing *
That addon is known as Cell Fracture. What I am suggesting, is maybe perhaps create a modifier for use with UPBGE that fractures objects based on a particle system. This is done by setting the object to a particle system in the “Particle System” field , and then you can play around with the modifiers Speed, Force, Drag, Velocity parameters and more. This is essentially an UPBGE Game Engine optimised version of the Particle Systems that are used in Blender and as it would be built from the ground up in UPBGE, it would be usable in the player. This would also solve the particle dilemma where you map an object to a particle emitter, press P and nothing. The Fracture part would only work if Fracture Object is clicked, in which you can then select the target object, otherwise it will work as a normal Game Engine particle system that doesn’t stop when P is pressed (this is what normal particles suffer from).
What I am referencing to is EasyEmit. I wonder if a similar particle system can be placed into a modifier for UPBGE (Game Engine use only). It would need to be adapted to 3.0, and would need to have a warning icon if you increase the particle number too much saying it could crash UPBGE. It could have what is known as “particle culling”, this works rather like how Activity Culling works, but seperate for particles. As it operates on the Particle System and a modifier base, it would solve the issue of static particles not being able to move UPBGE 0.3+, which is a bug in how applyMovement() and applyTorque() work, since this never happened prior to 0.3.
Or alternatively, just fix the movement bug with applyMovement and applyTorque that happens with Static objects. If I set a Static type object to move with 0.05 movement on the Y axis with applyMovement, it works as intended in 0.2x - the object moves, but not in 0.3+, as the object stays still which breaks particle movement effects without use of the Motion actuator. And if you think about it, Python can be used for more freedom of movement in particle objects. The same thing occurs with applyTorque - fine in 0.2x, not working for 0.3x in Static type objects, this should be seen and fixed by the developers…
Sorry I got a little heated on the bug part, but imagine working on a campfire, and then the flames don’t rise, meanwhile in 0.2x, they work fine. Baffling…
Idk, spawning or (adding group) always lags upbge. Its unfortunate. I typically have to resort to making sprite sheets for effects. Unless this is getting fixed soon.
It’s unnecessary to spawn it, you can place it there from the very beginning and just hide it and stop physics until it’s needed. Then unhide and re-enable physics at the proper moment.
That lags the game if to many objects are constantly loaded in game, even invisible and everything disabled on them. To many objects results in high dependency graph. Any solution to this?
You’re right, I’m not aware of solution to this one (other than going to the oldest version of the engine, based on Blender 2). One of the biggest problems for me as well. If you need just a few more objects because of this, it’s fine, but if you get hundreds more, it’s gonna be pretty bad for FPS. In this specific case, it might be possible to reuse those fragments again and again, but it sounds like it might make things more complicated than they really need to be be.
Most game engines (even older game engines on the N64) used a special system to deactivate objects once they are out of your camera’s view or a certain range. Think Minecraft for example.
I wonder how this would translate in UPBGE python?
You can write a script that actually creates a decimate modifier and checks for the LOD modifier using a flag or if the modifier exists in the object. You then check how far the viewer is away from said object, apply some math or something like that, and you now have your very own LOD modifier that updates in real time! This will also save depsgraph and CPU usage!
Back to the topic at hand, you could combine this method with a module that detects the FPS - if it drops below lets say 45, we start reducing the number of verts the added object has via a LOD module that is modified to reduce vertices based on how low the FPS is for the object - an FPS of 10 for example will result in an object having very few vertices, while an FPS of 50 results in full vertices.
I think this is how many old games handled framerate with many objects. Correct me if I’m mistaken.
We’re talking about something that doesn’t exist in any other engine. In UPBGE it will get laggy even if you create a lot of empty objects, their geometry is irrelevant. If you merge them all into a single object, lags magically disappear. This is because of Blender’s Depsgraph thing that got introduced with Eevee, it’s very slow and it needs to run every frame. It’s actually a bit more complicated because if you test it in empty scene, it will not reproduce. In my case, I’ve had a scene where just removing ~200 empties that don’t have any scripts or constraints attached results in ~20 fps increase. But this particular effect with empties was most pronounced in 0.43+, just downgrading to 0.36 I got most of that FPS from the start and after removing empties the increase is just 2-3 FPS.
PS: I don’t really know the history behind Blender development and BGE, but I noticed that original BGE was discontinued from Blender in 2.8, precisely the version where Eevee and Depsgraph were introduced. I guess they knew how much of disaster those systems will be to BGE and didn’t want to compromise and allocate efforts to optimize them to be usable in game engine context