How to assign a skeletal mesh from another actor?

Is there a way to get a SkeletalMesh from another actor or SkeletalMeshComponent and set it to mine?

What I’m trying to achieve and what I’ve tried:

I have a WeaponPickup class with WeaponClass property. When player collects pickup, weapon of given WeaponClass is spawned and given to the player. That works. The problem is that I’d like WeaponPickup look like actual weapon, because player want to see what they are about to pick up :slight_smile:

I tried duplicating weapon’s mesh from weapon CDO into WeaponPickup, but results in the assertion failure when Play in editor:

// I call this in the PostInitializeComponents and when the WeaponClass property is changed by editor
void AWeaponPickup::ReinitHeldWeapon()    
{
    ABaseWeapon* weaponCDO = WeaponClass != nullptr ? Cast<ABaseWeapon>(WeaponClass->GetDefaultObject()) : nullptr;
    if (!weaponCDO)
        return;

    USkeletalMesh*          mesh          = DuplicateObject(weaponCDO->GetMesh(), meshComponent);
    USkeletalMeshComponent* meshComponent = GetPickupSkeletalMesh();

    meshComponent->SetSkeletalMesh(mesh);

// Ensure condition failed: !(bDuplicateForPIE && DupObjectInfo.DuplicatedObject->HasAnyFlags(RF_Standalone)) [File:D:/Build/++UE4+Licensee/Sync/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp] [Line: 2103] 

There is a corresponding UE code:

/Engine/Source/Runtime/CoreUObject/Private/UObject/UObjectGlobals.cpp

UObject* StaticDuplicateObjectEx( FObjectDuplicationParameters& Parameters )
{
    // ...
    bool bDuplicateForPIE = (Parameters.PortFlags & PPF_DuplicateForPIE) != 0;

	// Any PIE duplicated object that has the standalone flag is a potential garbage collection issue
	ensure(!(bDuplicateForPIE && DupObjectInfo.DuplicatedObject->HasAnyFlags(RF_Standalone)));

So, it looks like I misuse DuplicateObject. Is there some way I can do such an assignment correctly?

Thanks in advance!

Did you ever find a solution to this? I get the same problem.

Yep, it looks like we don’t have to duplicate the mesh.
I’ve attached a screenshot, where on the WeaponClass change I’m getting a mesh from the WeaponClass CDO and assigning it as pickup’s mesh as well.