How to get a bone location in world space in C++?

I’m doing this in a ActorComponent of a Character.

here’s my code:

AActor* characterActor = NULL;

characterActor = GetOwner();

playermesh = Cast (characterActor->GetComponentByClass(USkeletalMeshComponent::StaticClass()));

FVector head_loc = playermesh->GetBoneLocation(“head”, EBoneSpaces::WorldSpace);

But I found that the result location head_loc is all zero.(0, 0, 0) what’s wrong with my code ?

Create a socket at that bone, then you can call

FVector Location = Character->GetMesh()->GetSocketLocation(SocketToUseName);

Also got zero vector, can I ask how to get the component’s character pointer?

Are you sure that the bone/socket name you are using is correct?

I have found the reason why I was incorrect.
I put the code in constructor, I should put in the BeginPlay function

Omg, using these functions in the constructor is not a good thing to do :stuck_out_tongue: