Announcement

Collapse
No announcement yet.

Item not attaching to actor on pickup C++

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    Code:
    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());
    }

    #2
    Verify socket...

    Code:
    ensure(GetMesh() && GetMesh()->DoesSocketExist("item_socket"));
    
    FTransform SocketTransform = GetMesh()->GetSocketTransform("item_socket");
    
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, SocketTransform.ToHumanReadableString());

    Comment


      #3
      Code:
       ItemActor->K2_AttachToComponent(Character->GetMesh(), FName(*SocketNames[i]), 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.

      Comment

      Working...
      X