I have two SkeletalComponent which contain same Skeletal Mesh. One SkeletalComponent Say “Comp1” has a AnimInstance that I want to do some skeleton transformation. And the second SkeletalComponent “Comp2” hopes to receive the “BoneSpaceTransform” of “Comp2”. I Use “SetRefPoseOverride” for “Comp2” while using the BoneSpaceTransforms of “Comp1”. But result show they are resulting in opposite pose.
Here is my test BluePrint code:
void UTestBluePrintBPLibrary::PrintBoneTreeName(float angle)
{
TArray<FAssetData> SelectedAssetData = UEditorUtilityLibrary::GetSelectedAssetData();
TArray<AActor*> Actors;
UGameplayStatics::GetAllActorsOfClass(GWorld, ASkeletalMeshActor::StaticClass(), Actors);
bool bIsInit = false;
TArray<FTransform> NewTransforms;
FName NeckBoneName = "Neck";
for(auto& Actor : Actors)
{
GWarn->Log(Actor->GetActorNameOrLabel());
auto SkeletalComponents = Actor->GetComponents();
if(!bIsInit)
{
for(auto& ActorComp : SkeletalComponents)
{
USkeletalMeshComponent* SkeletalMeshComponent = StaticCast<USkeletalMeshComponent*>(ActorComp);
NewTransforms = SkeletalMeshComponent->GetBoneSpaceTransforms();
TArray<FName> BoneNames;
SkeletalMeshComponent->GetBoneNames(BoneNames);
int32 BoneIndex = SkeletalMeshComponent->GetBoneIndex(NeckBoneName);
auto AnimInstance = Cast<UAnimPreviewInstance>(SkeletalMeshComponent->GetAnimInstance());
if(AnimInstance)
{
AnimInstance->Modify();
FTransform BoneTransform = SkeletalMeshComponent->GetBoneTransform(BoneIndex);
auto& ModifyNode = AnimInstance->ModifyBone("Neck");
ModifyNode.TranslationSpace = EBoneControlSpace::BCS_WorldSpace;
ModifyNode.Translation = BoneTransform.GetLocation() + FVector3d(angle * 0.01, -angle*0.02, angle * 0.03);
AnimInstance->Modify();
bIsInit = true;
}
}
}
else
{
for(auto& ActorComp : SkeletalComponents)
{
USkeletalMeshComponent* SkeletalMeshComponent = StaticCast<USkeletalMeshComponent*>(ActorComp);
auto RefTransforms = SkeletalMeshComponent->GetSkeletalMeshAsset()->GetRefSkeleton().GetRefBonePose();
int32 BoneIndex = SkeletalMeshComponent->GetBoneIndex(NeckBoneName);
GEngine->AddOnScreenDebugMessage(-1, 3, FColor::Blue, NewTransforms[BoneIndex].ToString());
GEngine->AddOnScreenDebugMessage(-1, 3, FColor::Red, RefTransforms[BoneIndex].ToString());
GEngine->AddOnScreenDebugMessage(-1, 3, FColor::Green, NewTransforms[BoneIndex].ToString());
SkeletalMeshComponent->SetRefPoseOverride(NewTransforms);
}
}
}
}
This BluePrint funtion will be could in EventTick.
Can any one could help me this out? I’m almost insane.
