# Controlling PhAT contraints during runtime

**URL:** <https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373>\
**Category:** Character & Animation\
**Tags:** unreal-engine\
**Created:** [January 6, 2015, 3:05pm UTC](https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373 "2015-01-06T15:05:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev100000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dev100000](https://forums.unrealengine.com/u/dev100000)\
**Post date:** [January 6, 2015, 3:05pm UTC](https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373/1 "2015-01-06T15:05:23Z")

</div>

Hi,

First, I would like to say that I am really surprised with UE4, especially the physics. I never did game writing, but have lots of background in 3D software and Coding.

I am trying to create a powered ragdoll which has walking/balancing algorithms to drive the joints/contraints.

Here is what I have done so far in my project (and which works nice!):

1. I migrated the HeroTPP physics asset from the physical animation example, 2. created a nice camera logic that takes gamepad input (blue print looks like a bowl of spaghetti; it is basically the GTA 5 camera replicated) 3. turned HeroTPP into blueprint and added gamepad input to apply force/impulse and so on to my ragdoll’s bones (HeroTPP), 4. I added some rocks/geometry etc from the starter content

So now I have my ragdoll that I can have fly through the level, throw down cliffs etc. This works really nice and in a realistic fashion by adjusting the contraints in the PhAT to the ‘contraints’ of a human body, i.e. the joints and their limits. So no matter how hard and from how high I form my ragdoll around, it always stays in natural poses when crashing down cliffs etc.

Here is my question:

Is it possible to adjust the PhAT constraint parameters (swing limits, overall rotation, etc.) during runtime.  
I did not find a way in blueprints, so I guess functions that can access and change the parameters need to be created from scratch by myself in C++.

I found ‘add torque’, ‘add angular velocity’ under Physics in the blueprint, and they work, but they do not serve me well. I need to change the constraint parameters directly to create something like a walking robot, but completely animation free.

There is this small game SUMOTORI, which has self-balancing ragdolls. There you can get the idea.

---

<div class="post-metadata">

**Author:** ![Exelcior](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Exelcior](https://forums.unrealengine.com/u/Exelcior)\
**Post date:** [January 7, 2015, 3:03pm UTC](https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373/2 "2015-01-07T15:03:10Z")

</div>

Hey dev100000,

You’re right that this is probably beyond the scope of the blueprint functions at the moment. Although it should be possible in code. You can access joints for a skeletal mesh through USkeletalMeshComponent::FindConstraintInstance providing the name of a constraint, or access joint array USkeletalMeshComponent::Constraints directly. Within FConstraintInstance there’s a bunch of methods for setting/updating the limits, drives and positions for the joint.

Hope that helps!

Benn.

---

<div class="post-metadata">

**Author:** ![dev100000](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dev100000](https://forums.unrealengine.com/u/dev100000)\
**Post date:** [January 7, 2015, 4:48pm UTC](https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373/3 "2015-01-07T16:48:55Z")

</div>

Hi Benn,  
Thank you for your reply.  
It is good to know that C++ Code can access skeletal mesh PhAT constraints.  
When I look at the PhAT constraints, they are just normal constraints. So I was actually hoping that accessing them is possible, but that it has simply not been implemented yet into blueprints. It is not a common use case for UE4 after all to do self balancing ragdolls, or ‘powered’ ragdolls. If it works however, and with the rock-solid UE4 physics it should, then having truly animation-free gameplay would be amazing. Especially with the human-like PhAT constraints that already work so well, as described above.  
Looking forward to digging into C++ again and to creating ragdoll walk, jump etc. algorithms that are aided by self-balancing during the course of the next months!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0500cf20](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0500cf20](https://forums.unrealengine.com/u/anonymous_user_0500cf20)\
**Post date:** [November 4, 2016, 4:06pm UTC](https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373/4 "2016-11-04T16:06:05Z")

</div>

Here’s some sample code for doing this, in case anyone’s still looking. Quick function I wrote in a C++ Blueprint Function library to update the orientation target of a constraint’s angular motor. You can look up definition of “FindConstraitInstance” and should be able to call any of its set functions the same way I’m calling SetAngularOrientationTarget here.

**MyBlueprintFunctionLibrary.cpp**

> [@](#):
>
> #include “[MainProjectSourceFile].h”  
> #include “MyBlueprintFunctionLibrary.h”  
> #include “Runtime/Engine/Classes/PhysicsEngine/ConstraintInstance.h”
> 
> void UMyBlueprintFunctionLibrary::SetOrientationTarget(USkeletalMeshComponent\* TargetMesh, FName ConstraintName, FRotator OrientationTarget) {
> 
> ```
> TargetMesh-&gt;FindConstraintInstance(ConstraintName)-&gt;SetAngularOrientationTarget(OrientationTarget.Quaternion());
> 
> ```
> 
> }

---

<div class="post-metadata">

**Author:** ![Nonlin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nonlin](https://forums.unrealengine.com/u/Nonlin)\
**Post date:** [June 6, 2019, 3:30pm UTC](https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373/5 "2019-06-06T15:30:41Z")

</div>

> [@Exelcior](#):
>
> Hey dev100000,
> 
> You’re right that this is probably beyond the scope of the blueprint functions at the moment. Although it should be possible in code. You can access joints for a skeletal mesh through USkeletalMeshComponent::FindConstraintInstance providing the name of a constraint, or access joint array USkeletalMeshComponent::Constraints directly. Within FConstraintInstance there’s a bunch of methods for setting/updating the limits, drives and positions for the joint.
> 
> Hope that helps!
> 
> Benn.

Would this also allow changing a Bodies position at runtime as well?

EDIT:Not body but PxShape?

---

<div class="post-metadata">

**Author:** ![mightyenigma](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mightyenigma](https://forums.unrealengine.com/u/mightyenigma)\
**Post date:** [November 29, 2021, 3:49pm UTC](https://forums.unrealengine.com/t/controlling-phat-contraints-during-runtime/18373/6 "2021-11-29T15:49:53Z")

</div>

Works great! Thanks. I just had to add some nullptr checks to prevent crashes if the constraint name is spelled wrong
