How to get socket location from PlayerController?

I’m trying to get the location of a socket in a PlayerController.

I figured I would have to get the USkeletalMeshComponent of the character but I didn’t have much luck with this.

Here is my current solution:

ACharacter* const character = Cast<ACharacter>(GetPawn());
if(character)
{
	// Code crashes on this line
	USkeletalMeshComponent* skeletalMesh = Cast<USkeletalMeshComponent>(character->FindComponentByClass(TSubclassOf<USkeletalMeshComponent>()));

	if(skeletalMesh)
	{
		FVector start = skeletalMesh->GetSocketLocation("root");
	}
}

What’s the proper way to do this?