Download

Item not attaching to actor on pickup C++

For some reason my Item is not attaching to my characters item socket. Here is my code. I been looking and have not found anything that works. It makes it to the debug message.



void AHumanoidCharacterActor::PickupFocusedItem()
{
  UItemActorComponent* ItemActorComponent = UItemActorComponent::GetPlayerFocusedItem(this, 220, true);
 if (ItemActorComponent == nullptr)
  return;

 AActor* ItemActor = ItemActorComponent->GetOwner();
 ItemActor->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, "item_socket");

 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, ItemActor->GetName());
}


Verify socket…



ensure(GetMesh() && GetMesh()->DoesSocketExist("item_socket"));

FTransform SocketTransform = GetMesh()->GetSocketTransform("item_socket");

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, SocketTransform.ToHumanReadableString());



 ItemActor->K2_AttachToComponent(Character->GetMesh(), FName(*SocketNames*), EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, true);

Ok SO I’m using K2_AttachToComponent and It works. I have no idea why or what K2 means. I don’t like not knowing and why is there so many Attach functions. When It comes to simplicity sometimes Unreal just weird compared to Unity from a programming perspective. Thanks for the Reply empty2fill.