Greetings, fellow developers!
Recently, i’ve encountered strange bug. Call SetupAttachment from CameraBoom component, the way like this:
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(GetMesh(), FName("head"));
CameraBoom->TargetArmLength = 0.0f; // The camera follows at this distance behind the character
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
Nothing happens.Blueprint shows, that camera boom does not attached to the skeletal socket.
Also, as result of the DoesSocketExists i’m receiving false result. “head” socket exists in the skeleton.
Can somebody help, please?
In case listed below, CameraBoom and FollowCamera even not creating…
if (GetMesh()->DoesSocketExist(FName(TEXT("head")))) {
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(GetMesh(), FName(TEXT("head")));
CameraBoom->TargetArmLength = 0.0f; // The camera follows at this distance behind the character
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
FollowCamera->bUsePawnControlRotation = true; // Camera does not rotate relative to arm
}
“head” isn’t a socket, its a bone from looking at your hierarchy. Though I haven’t touched skeletal meshes in a while so it might be possible to though I’ve never tried it. “weapon” however is a socket.
I know this is and old post but I had this exact problem and found the solution, the issue is that the new attachment setup is not being updated to force the update you have to rename your component from CameraBoom to something else in the CreateSubobject function, this way you’ll be able to see the change or create a new USpringArm but make sure you indicate the socket name before compiling or else you’ll face the same problem.
The issue is still present in 4.26.1. Built from source. Both SetupAttachment and AttachToComponent are broken. C++ and BP, in constructor and in BeginPlay. Same result with bones and sockets. Using correct FName initialization. This feature breaks seemingly at random, and there’s no reliable way to fix it yet AFAIK.