# How to set lock rotation at runtime?

**URL:** <https://forums.unrealengine.com/t/how-to-set-lock-rotation-at-runtime/379824>\
**Category:** Community & Industry Discussion\
**Tags:** Constraints, rotation, unreal-engine, lock, question\
**Created:** [December 20, 2016, 7:44pm UTC](https://forums.unrealengine.com/t/how-to-set-lock-rotation-at-runtime/379824 "2016-12-20T19:44:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davision](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Davision](https://forums.unrealengine.com/u/Davision)\
**Post date:** [December 20, 2016, 7:44pm UTC](https://forums.unrealengine.com/t/how-to-set-lock-rotation-at-runtime/379824/1 "2016-12-20T19:44:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Spoondog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Spoondog](https://forums.unrealengine.com/u/Spoondog)\
**Post date:** [January 16, 2018, 3:33am UTC](https://forums.unrealengine.com/t/how-to-set-lock-rotation-at-runtime/379824/2 "2018-01-16T03:33:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ashe23](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ashe23](https://forums.unrealengine.com/u/ashe23)\
**Post date:** [January 15, 2021, 11:36am UTC](https://forums.unrealengine.com/t/how-to-set-lock-rotation-at-runtime/379824/3 "2021-01-15T11:36:42Z")

</div>

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.

![327275-2021-01-15-15-25-10.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/3/6a34e24233853697a7a323702ee78d7f14d28fbc.png)

```
// 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);
}
```
