Event tick with Wake rigid body? UE5

Hi all,
I am working on a game and wanted to know, would it be bad to put a ‘wake rigid body’ node on one of my objects in game? I am trying to keep the system requirements for running the game pretty low. Is this a bad use of an event tick or is it ok?
If it is a bad idea/bad practice, how should I keep a liftable object awake when it is sitting in a place the player cannot immediately reach? I am hoping to have a platform rotate to drop the item when the player presses a button. All of the functionality is working with this setup but want to know if there is a more efficient way to do this.
Thanks!

Hey there @Miss_Alexis! Welcome to the community! So generally if at all possible try to avoid putting anything in event tick that can be triggered by an event such as coming in range of something, casting, or even rendering it! The reason sleep is so aggressive is due to the fact it’s expensive to run collisions on everything constantly with full fidelity. The good news is there’s a way to disable sleeping altogether for specific objects if you’d like.

You can make a physics material and apply it to your object as an override:
image

And you can change all of these to 0 on the physical material itself:

Now your object will never sleep. I do however recommend changing this material in and out with one that allows it to sleep when it’s done being used in a larger game requiring more performance, but in smaller games you could leave them awake if you’d like. In my own experience I tend to send wake up events and change them to this material while I’m within 1000u but in your case if you’re doing Portal like levels where the player may not be in range to be near them it might just be better to leave them awake and just unload the whole room when you’re done.

Hope this helps!

1 Like

Somehow this doesnt work for me anymore in UE5.1.
I critically paid attention that i put the material on any component that is simulating physics. Anybody else still has this problem?

Hey there @apfelbaum! I hadn’t given this a fresh shot in 5.1 but the method should still work, is it still calling sleep/wake events?

grafik

grafik

When the car spawns this event is never fired. I have to press the throttle button while UE5 loads into PIE so probably on first tick there is force acting on the car.

PS. The CV is just a mesh with a UCX collision that i attach at runtime. it is the collider for the ground in shape of the car. It has the physical material assigned.

It doesn’t matter how Sleep Counter is set.

@SupportiveEntity

I can’t quite replicate the issue myself, I’m going to make a composite actor like yours to give it another try but I can’t get anything to fall asleep at all with the NoSleep physical material. Does the actor itself have generate wake events on? I think newly generated actors tend not to have it, I can’t speak for the baseline.

Does the physical material work for non-composite actors at all?

So now I set the variable “bGenerateWakeEvents” and it wakes up the rigid body. But when the car is resting it wakes up every frame until you move it again. I guess this is not the point of setting the physical material parameters so the vehicle is not put to sleep. for now it works.

You’re right, it shouldn’t be falling asleep at all, the difference seems in that it’s a C++ actor instead of a BP actor, so I think something with the defaults are likely at play. Are the “StartAwake” bool of all of the components that have the physical material set to true? Does ACar inherit from any other class but actor?

ACar inherits directly from APawn. I can try setting StartAwake to true. Yes it is code only.

Gotcha, Pawns are actors so it should work out. I’m going to create a composite pawn myself in C++ to test where it could be ignoring the physical material override.

Edit: Composite actor is for some reason not caring about the physical material override. I’m off for the night but it could be that it’s taking on the collision profile of it’s parent (which if the scene root isn’t something that takes a physical material override it’d be stuck with the default). Will do more testing when I come back in tomorrow night!

1 Like

So setting this bStartAwake on the BodyInstance to true does not prevent the car from falling asleep permanently. It is the Materialoverride?

I believe the materialoverride is just overriding the material for SMs (which you can technically make a material that has a physical material but the override is good), you had the right call for setting the physical material override.

Was the material override set for the root box component as well? Since the root is what all of these inherit that could be it. I see you call wake on it but don’t see where it’s override occured.

image

I set it a few lines above on the BodyInstance of the BoxComponent :slight_smile:

Edit: I guess it is enough to call this on the RootComponent and all welded components get it too right?

Yep, root component decides the physics profile of all welded ones, you got it!

I fooled around a bit with it. The event still triggers very often and the body is woken up most often. But sometimes it doesn’t wake up but the function is still triggeres every frame.
Also I set the following on BeginPlay, hope this is not too late?

	BodyInstance->bStartAwake = true;
	BodyInstance->SleepFamily = ESleepFamily::Custom;
	BodyInstance->CustomSleepThresholdMultiplier = 0.0f;
	BodyInstance->bGenerateWakeEvents = true;
	BoxComponent->OnComponentSleep.AddDynamic(this, &ACar::OnSleep);

All of those should be fine to fire on BeginPlay, but the physical material override should be added before it starts simulating if possible, which I think you already did. This is a bit of a fun one in the sense I can get the blueprint variant of this to work without a hitch, but the C++ version doesn’t.

I also checked during PIE when I select the car, the BoxComponent is showing the physical material in the corresponding slot in the details panel.

Edit.: I override the physical material way after begin play. The car is pooled (spawned, hidden, collision response disabled, not ticked…). When I need a car I grab it from the pool and initialize all properties. I also set the physical material before I activate collision response etc. After the car has been fully loaded (FStreamableManager) and everything is set on it I unhide and enable its collision response again.

I’m completely dumbfounded on why this variant wouldn’t be working. All of the constituent parts are welded and have the physical material anyway.