How to set spawned static object to sleep?

I have encountered a thing that happens when I spawn a static object as an obstacle in-game.
I use a lot of rigid body objects and I want them to sleep when I put them on that obstacle static object.
This works when I have these obstacles already in the main frame. But when I spawn these obstacles and put rigid body objects on top of them, they are never put to sleep and keep on jittering.
I can clearly see that when I turn on the Physics visualization under the debug menu.
Already existing obstacle in the main frame is green, but a spawned one is white.
Is there a way to set spawned static objects to sleep?
Turn them from white to green in physics visualization?

I did simething similar here:

And I also use this:
Restore_disable

Suspend/restore physics and Enable/disable rigid body

Maybe it helps I dunno, its kinda hard to understand without a video or some sample file

The thing is, it’s a static object, it isn’t supposed to have any dynamics turn on. But if I move it a little, it will keep on calculating collision or location forever. So no rigid body object will stop when colliding with this object.

What I said before.

can you recreate a sample file in wich the same thing happens?

Spawned_static_object-TEST.blend (530.2 KB)
Here you can test it.
On the left is a static object already present in the main-frame and on the right is a spawned in static object.
You should have the Show Physics Visualization enabled to see if the object is sleeping or not.
Right from the start, you can see a green outline on the left object and white on the right.
When you press SPACE, you’ll spawn in rigid body objects. Keep on pressing SPACE to spawn more.
You’ll see that on the left, the rigid body objects will enter sleep mode, and on the right, they remain sleepless.
These static objects are identical but one is spawned in. The same happens when I move the object. Its outline will change to white and never back to green.
Is there a way to set the static object back to the sleep mode / green outline?

UPDATE: So it seems that, if I give the spawned object a logic brick to suspend Dynamics, it works.
But it works only with a single spawned object or a parent object. Child objects are unaffected by this.
This is the same with Group instance. The objects inside the group play the same role as child objects, so they are unaffected by suspend Dynamics actuator.
This is bad since I’m spawning group instance and not a single object in my game.
I even tried a python script for example:

added_object = own.scene.addObject('GroupStatic', own, 0)
    added_object.groupMembers["StaticPart"].suspendDynamics()

That won’t show any error in the System console and does nothing at all.
This is a Blender example with spawning a Group instance.
SPACE to spawn rigid body objects.
Spawned_static_object-TEST2.blend (517.4 KB)

I saw you were using Activity Culling, but the camera is too close, I think… so physics and logic wont be disabled at all, and maybe this is the reason objects keep jittering.

I did a similar thing in my game demo, I constantly replace objects and at certain distance for another ones with no collision and things like that.

So I came up with this solution, maybe is not the best approach but it works for me, hope it helps! :slight_smile:

Here is what I got:
hXF89a8NVj

Spawned_static_object-TEST1.blend (510.4 KB)

This is very interesting way and I might use it in some way.
But the collision isn’t perfect with this as seen with the rigid body objects suddenly shoot out of the scene.
What did you set up in the Rigid Body object sensor? It’s empty for me.
Pic_001

This is quite common, I mean, sometimes objects falls from floor on big scenes, or get shoot out…, but might depend how is configured in thr world settings, or might be because at the beginning the chamfered object (rigid body and static) has some rotation info on it, and I duplicated changed to “static” and maybe I applied Ctrl+A and the bounding box changed a little bit, thats why when the replacement happend, collision boundaries are a bit different and then objects suddenly collides.

I did this in my game too, and is not common to see, so I would start looking at that two options to check.

Are you using UPBGE? I’m using it, Is the “movement” sensor.

No, I’m using just the BGE and there is no movement sensor but for some reason it works.
But replacing the object is really great idea. Can you do this with camera? When you are a certain distance from the object, to replace the object or mesh with low poly model?

1 Like

I think it works because of the “delay” sensor, because its importan to know when the objects stops moving in order to work properly, but who knows :slight_smile:

Yeah its possible, in my video of my game demo I use that. At a certain distance I disable all the physics and logic from the player to any other object, also I replace the object with another one but with “no collision” but with a sensor asking for the player, if close enough then the physics object is back.

While playing the game its unoticeable for the player, and that way help me to preserve decent fps, but anyway you need to plan very well as usual your game levels, or look for a way to determine were you are able to construct, to avoid too much blocks near to you… things like that :slight_smile:

This is a test level I did inside my game, as you can expect every block (stair, pillar, wall, wall with window and so on) has its own duplicate but with “no collision”

In this video, I only apply the “end object” , but there is no other object , just to see if this works, so it looks like the entire level is created as you walk:

And I did the same with this turrets, I add them or delete them when needed, if you are too far then I replace the turret with just an empty, and that empty add the turret when the player is close enough, very basic but it works :slight_smile:

1 Like

Thanks for those tips, they are very useful.
By the way, is that a full game or just a concept? That game mechanics look great.

1 Like

I’m glad to help! :slight_smile:

Thanks man! means a lot
I’m trying to make a full game, and in the mean while I enjoy the process :sweat_smile:

Hope to see your game project soon !

Since I’ve seen your procedurally l generated level, I’ve been wondering if I should do the same.
But isn’t it too taxing to always generate parts of the level?
I thought to change the model to low poly or changing models for static objects would be enough.
Or is it better to delete the object and leave just an empty and then create a new one when you return?

Make some test to see how it behave it would be great to see some of your game test :slight_smile:

Being made in this way, I think the answer is yes. The optimal way I think would be using geometry batch, but I at least in my game I’m trying to make everything with logic bricks and logic nodes.

I prefer to replace all collision object with other identical object but with no collision, and at certain distance delete the no collision object and put a empty, that empty will put the no collision object, and when you are close enough to interact, then replace with the collision object.

I even tested with ocluder object, I mean the same cube acts as ocluder so any other object behind it will be hided, you can notice in this video when I look at the structure some cubes seem to be flickering, that’s why.

There are like 1000 cubes on scene, and it works fine.

Just a note: in this video I haven’t implemented the replacement for a non collision object, thats why FPS is a bit lower.