In the Physics settings under Constraints you can set lock rotation but there seems nothing for it to set it at runtime through blueprint? There is a constraint mode node but that seems useless (for rotation) since it only lets you set a mode and not its settings. What am I missing here?
1 Like
Being able to set Lock Rotation at runtime through blueprints would be great - it seems like they are slowly exposing more of these physics settings to Blueprint but this one has slipped under the radar.
You can access constraint data via c++ code.
Below is example how to lock constraint rotation runtime.
Constraint Name must be copied from Physical asset of your skeletal mesh.
// headers
#include "PhysicsEngine/ConstraintInstance.h"
FName ConstraintName{"YourConstraintName"};
FConstraintInstance* Constraint = GetMesh()->FindConstraintInstance(ConstraintName); // GetMesh() <- your skeletal mesh
if(Constraint)
{
Constraint->SetAngularSwing1Motion(EAngularConstraintMotion::ACM_Locked);
}
// Or you can expose function to Blueprint for more convinient way
// .h file
UFUNCTION(BlueprintCallable)
void LockConstraintRotation(const FName& ConstraintName);
// .cpp file
void YourClass::LockConstraintRotation(const FName& ConstraintName)
{
FConstraintInstance* Constraint = GetMesh()->FindConstraintInstance(ConstraintName);
if(!Constraint) return;
Constraint->SetAngularSwing1Motion(EAngularConstraintMotion::ACM_Locked);
// other methods available
//Constraint->SetAngularSwing1Limit(EAngularConstraintMotion::ACM_Limited, Angle);
//Constraint->SetAngularSwing1Motion(EAngularConstraintMotion::ACM_Limited);
//Constraint->SetAngularSwing2Limit(EAngularConstraintMotion::ACM_Limited, Angle);
//Constraint->SetAngularSwing2Motion(EAngularConstraintMotion::ACM_Limited);
}