How can I keep a Skeletal Mesh Component from falling asleep in C++ without calling WakeAllRigidBodies() every frame? I want to configure the skeletal mesh before it starts ticking so I don’t have to tell it NOT to do something every frame, which is silly. I know how to do this from the editor, which is to go into the SMC’s physics asset, select all bodies, then set sleep family to custom and custom sleep threshold multiplier to 0.
I’ve tried this code…
UPhysicsAsset* upa;
if (PhysicsAssetOverride == nullptr) {
upa = GetPhysicsAsset();
}
else {
upa = PhysicsAssetOverride;
}
for (auto sbs : upa->SkeletalBodySetups) {
sbs->DefaultInstance.SleepFamily = ESleepFamily::Custom;
sbs->DefaultInstance.CustomSleepThresholdMultiplier = 0.f;
}
but it doesn’t do what I need. It does not prevent the SMC from sleeping, but it does modify the values of the sleep family and threshold in the physics asset in the editor. I’ve also tried the following which didn’t seem to work either:
UPhysicsAsset* upa;
if (PhysicsAssetOverride == nullptr) {
upa = GetPhysicsAsset();
}
else {
upa = PhysicsAssetOverride;
}
TArray<FName> bone_names;
GetBoneNames(bone_names);
if (bone_names.Num() > 0) {
for (const auto& name : bone_names) {
FBodyInstance* fbi = GetBodyInstance(name);
if (fbi != nullptr) {
fbi->SleepFamily = ESleepFamily::Custom;
fbi->CustomSleepThresholdMultiplier = 0.f;
}
}
}
I’d prefer a solution that doesn’t require adding the PhysX module as a dependency to my plugin I’m making.