void AItem::AttachItemToNed_Hand() { ARoadFeverCharacterNed* PlayerCharacter = Cast<ARoadFeverCharacterNed>( GetWorld()->GetFirstPlayerController()->GetPawn() ); USkeletalMeshComponent* NedsCharacterMesh = PlayerCharacter->GetMesh(); bCanBePickedUp = false; if ( NedsCharacterMesh ) { AttachRootComponentTo( NedsCharacterMesh, FName( TEXT( "ItemPoint" ) ), EAttachLocation::SnapToTarget ); DetectionBox->DestroyComponent(); } }
void AMagicBattleSoccerWeapon::AttachMeshToPawn(FName InSocketName) { if (nullptr != MyPawn) { // Remove and hide both first and third person meshes DetachMeshFromPawn(); // Attach the weapon to the player's right hand USkeletalMeshComponent* PlayerMesh = Cast<USkeletalMeshComponent>(MyPawn->GetComponentByClass(USkeletalMeshComponent::StaticClass())); AttachRootComponentTo(PlayerMesh, InSocketName, EAttachLocation::SnapToTarget); // Show our mesh SetActorHiddenInGame(false); } }
// Equip Start void AWeapon::EquipStart() { if (!ThePlayer)return; // BP Equip Start BP_Equip_Start(); // Attach First person Mesh if (Mesh1P) AttachRootComponentTo(ThePlayer->Mesh1P, FName("WeaponSocket")); // Attach Third Person Mesh if (Mesh3P) Mesh3P->AttachTo(ThePlayer->GetMesh(), FName("WeaponSocket")); // Load Weapon Data from inventory if (ThePlayer && ThePlayer->TheInventory) { for (int32 i = 0; i < ThePlayer->TheInventory->Items.Num(); i++) { if (ThePlayer->TheInventory->Items.IsValidIndex(i) && ThePlayer->TheInventory->Items[i].Archetype && ThePlayer->TheInventory->Items[i].Archetype->GetDefaultObject() && ThePlayer->TheInventory->Items[i].Archetype->GetDefaultObject()->GetClass() == GetClass()) { MainFire = ThePlayer->TheInventory->Items[i].MainFireStats; AlternativeFire = ThePlayer->TheInventory->Items[i].AltFireStats; break; } } } // Delay equip end FTimerHandle myHandle; ThePlayer->GetWorldTimerManager().SetTimer(myHandle, this, &AWeapon::EquipEnd, EquipTime, false); }