x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Transform skeletal bone in C++

Hello!

Is there way to transform bone of ASkeletalMeshActor? I tried to do it following ways:

(SkeletalMeshComponent from actor instance)

1) by changing SpaceBases and LocalAtoms for required bone

             auto BoneIdx = SkeletalMeshComponent->GetBoneIndex(TEXT("SheKRArm2"));
             SkeletalMeshComponent->LocalAtoms[BoneIdx].AddToTranslation(FVector(100, 100, 100));
             SkeletalMeshComponent->FillSpaceBases();
 

2) by applying body transform using PhysX

             auto Transform = SkeletalMeshComponent->SpaceBases[BoneIdx] * SkeletalMeshComponent->ComponentToWorld;
             Transform.AddToTranslation(FVector(100, 100, 100));
             SkeletalMeshComponent->GetBodyInstance(TEXT("SheKRArm2"))->SetBodyTransform(Transform, true);
 

So, what wrong I do?

Thanks.

Product Version: Not Selected
Tags:
more ▼

asked Jun 20 '14 at 11:59 AM in C++ Programming

avatar image

Numat
26 2 3 6

avatar image Deus0 Feb 03 '15 at 01:28 PM

Was this ever solved? It looks like the bone data is private except for the names: FReferenceSkeleton* RefSkeleton = &Mesh1P->SkeletalMesh->RefSkeleton; for (int32 i = 0; i < DebugRequiredBones; i++) DebugBoneNames.Add(RefSkeleton->GetBoneName(i));

I would like to get the positions and change them if possible :/ arg..

(comments are locked)
10|2000 characters needed characters left

4 answers: sort voted first

I don't think Rama's answer really addresses the question because it involves blueprints. That being said I'd still consider it still useful.

Transform Bones in C++ Only

ou'll have to inherit from UAnimInstance and override EvaluateAnimation. Once you've done that you can use USkeletalMeshComponent::SetAnimInstanceClass on a Skeletal Mesh Component to your new inherited anim instance.

EvaluateAnimation and FPoseContext is pretty undocumented at this point, but it's fairly simple to figure out.

Hope that helps! It sure helped me once I found it.

more ▼

answered Feb 02 '15 at 03:00 AM

avatar image

Zaucy
676 15 11 127

(comments are locked)
10|2000 characters needed characters left

Hello,

There is a UPoseableMeshComponent class that allow you to manually move any bone in the C++ code. You can use it instead of USkeletalMeshComponent and set any transformation to the LocalAtoms[].

Worked perfectly for me, though I don't know is it possible to add an animation blueprint to it (if you need one).

more ▼

answered Feb 06 '15 at 05:31 PM

avatar image

Dest8
41 1 2 10

(comments are locked)
10|2000 characters needed characters left

Skeletal Controller Single Bone + Custom C++ Anim Instance

In your Anim BP

Make a Skeletal Controller for Single Bone

Extend your Anim BP class, making your own AnimInstance class that has your custom FTransform or FVector or FRotator Vars in it

Then set these vars any time from anywhere c++ after accessing your custom anim instance.

You can even implement custom logic in the tick of the animation instance itself!

My Wiki Tutorials

Custom Anim BP Vars in C++

https://wiki.unrealengine.com/Animation_Blueprint,_Set_Custom_Variables_Via_C%2B%2B

Custom Logic in Anim BP Tick in C++

https://wiki.unrealengine.com/Animation_Blueprint,_Implement_Custom_C%2B%2B_Logic_Via_Tick_Updates

Advantages

You can modify animations that are playing if the Skeletal Controller is applied after the animation blends / montages / Slots

It's easy to use

Can do it with multiple bones and handle each case separately without one interfering with the other, enabling/disabling each modification as per your C++ logic / gameplay flow

Enjoy!

Rama

more ▼

answered Jun 20 '14 at 08:35 PM

avatar image

Rama
10.5k 444 343 1081

avatar image Numat Jun 25 '14 at 05:16 AM

Thanks Rama, but is there way w/o using BP ?

(comments are locked)
10|2000 characters needed characters left

Hi,

There is a UPoseableMeshComponent class that allow you to manually move any bone in the C++ code. You can use it instead of USkeletalMeshComponent and set any transformation to the LocalAtoms[].

Could you explain how you converted class USkeletalMeshComponent to class UPoseableMeshComponent ? I am almost in the same situation as Numat, the only difference is that I work with the ACharacter class.

more ▼

answered Jun 01 '15 at 06:49 AM

avatar image

Swall
26 1 3 3

avatar image Dest8 Jun 01 '15 at 11:48 AM

Hi,

You can't convert it. You need to create the UPoseableMeshComponent instead of USkeletalMeshComponent, and then you can set the same mesh to poseable component

avatar image Swall Jun 01 '15 at 11:59 AM

First of all, thank you for answering my question.

Could you show me a sample code for Acharacter class?

avatar image Dest8 Jun 02 '15 at 11:28 AM

Hi Swall,

Here is an example how to create a posable mesh in C++:

USkeletalMesh* yourMesh = .....;

UPoseableMeshComponent* posableMeshComponent = PCIP.CreateDefaultSubobject(this, TEXT("MeshComponent"));

posableMeshComponent->SetSkeletalMesh(yourMesh);

You can do this in your ACharacter class instead of creating the USkeletalMeshComponent.

avatar image Swall Jun 02 '15 at 06:35 PM

If I do as you say, I'll have the same results that I already have.

  • 2 characters

    static ConstructorHelpers::FObjectFinder skeletalMesh1(TEXT("SkeletalMesh'/Game/ThirdPerson/Character/ThirdPersonSkeletalMesh.ThirdPersonSkeletalMesh'")); Mesh->SetSkeletalMesh(skeletalMesh1.Object); MeshComponent = ObjectInitializer.CreateDefaultSubobject(this, TEXT("Mesh")); MeshComponent->SetSkeletalMesh(skeletalMesh1.Object); RootComponent = MeshComponent;

How do I change to avoid having duplicates?

alt text

screen.png (362.2 kB)
avatar image Swall Jun 03 '15 at 12:07 PM

If someone has a better solution that does not hesitate

 AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer) 
 {
     static ConstructorHelpers::FObjectFinder<USkeletalMesh> skeletalMesh1(TEXT("SkeletalMesh'/Game/ThirdPerson/Character/ThirdPersonSkeletalMesh.ThirdPersonSkeletalMesh'"));
     GetMesh()->SetSkeletalMesh(NULL);
 
     MeshComponent = ObjectInitializer.CreateDefaultSubobject<UPoseableMeshComponent>(this, TEXT("MeshComponent"));
     MeshComponent->SetSkeletalMesh(skeletalMesh1.Object);
     MeshComponent->SetMobility(EComponentMobility::Movable);
     RootComponent = MeshComponent;
 
     GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
     UCapsuleComponent* capsule = this->GetCapsuleComponent();
     capsule->AttachTo(RootComponent);
 
     // Create a camera boom (pulls in towards the player if there is a collision)
     CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
     CameraBoom->AttachTo(RootComponent);
     CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character    
     CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
     
     // Create a follow camera
     FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
     FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
     FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
 }

alt text

Disadvantage is that my character class has no mesh :-(

screnn.png (282.4 kB)
avatar image Dest8 Jun 03 '15 at 12:33 PM

If you need to use it in the ACharacter class I think you need to use that UPoseableMeshComponent instead of the character Mesh, not creating it beside the skeletal one. Try to not use and initialise the ACharacter::Mesh at all.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question