Hi guys!
I am kind of stuck at a problem I ran into. I want to attach my Weapon Blueprint to the Character Socket.
.cpp
const USkeletalMeshSocket* weaponSocket;
weaponSocket = GetMesh()->GetSocketByName(FName("WeaponSocket"));
FName fnWeaponSocket = weaponSocket->GetFName();
Debug::Log(fnWeaponSocket.ToString());
m_cUClassWeapon = StaticLoadClass(UObject::StaticClass(), nullptr, TEXT("/Game/Blueprints/CharacterController/BP_Pistol.BP_Pistol_C"));
m_cWeapon = GetWorld()->SpawnActor<AWeapon>(m_cUClassWeapon, spawnParams);
m_cWeapon->AttachRootComponentToActor(this, fnWeaponSocket, EAttachLocation::SnapToTarget, true);
The problem is that Unreal obviously does not find the Socket which I attached to the Skeletal Mesh in Editor.
The engine always attaches the weapon to the center of my character.
When I print the Variable on Screen in Line 5 I get the Name “SkeletalMeshSocket_0”, which is obviously not the name I gave the socket but seems to me like some kind of intern name?
What really bugs me is the fact, that when I build the same structure with blueprints it works perfectly and the weapon snaps to the selected socket.
So I just want to know, did I miss something in code or is this some unreal related bug?
Thanks for helping!