Hi there,
I am trying to dynamically attach an object to a skeletal component (a hand).
For this I am using Physics Constraints since physics will be important for me. However, when I attach the object to the hand it snaps to an offseted position (see video). In the video the Skeletal Mesh was part of a Character.
I also tested this where the skeletal mesh was an individual Actor (a floating fixed hand in the air) and the same issue appeared (see video).
However, if I use a StaticMesh to attach the object (a floating fixed brown cylinder), it works as supposed to: the constraint is created, and the object remains in its current position (see video).
The code for creating the constraint:
// .H
// Constraint component
UPhysicsConstraintComponent* MConstraintComp;
// Hand skeleton as fixed actor
ASkeletalMeshActor* HandSkelAct;
// Brown cylinder as fixed static mesh actor
AStaticMeshActor* StaticMeshAct1;
// Gray cylinder falling down and attaching the constraint to
AStaticMeshActor* StaticMeshAct2;
// .CPP
// CONSTRUCTOR
// Create the physics constraint
MConstraintComp = CreateDefaultSubobject<UPhysicsConstraintComponent>(TEXT("MFixatingGraspConstr"));
[..]
// Constraint action binding function
void MyCharacter::OnCreateConstraint()
{
if (!bAttached)
{
//Set World Location
MConstraintComp->SetWorldLocation(HandSkelAct->GetActorLocation());
//Attach
MConstraintComp->AttachToComponent(HandSkelAct->GetRootComponent(), FAttachmentTransformRules::KeepWorldTransform);
// Add the constraint components
MConstraintComp->SetConstrainedComponents(
HandSkelAct->GetSkeletalMeshComponent(), NAME_None, /* OR StaticMeshAct1->GetStaticMeshComponent(), NAME_None,*/
StaticMeshAct2->GetStaticMeshComponent(), NAME_None);
bAttached = true;
PrintGreen(TEXT("Attached!"));
}
else if (bAttached)
{
MConstraintComp->BreakConstraint();
bAttached = false;
PrintRed(TEXT("Detached!"));
}
}
Am I doing something wrong, or this is a bug?
Thanks!