Can't copy actor to another actor variable

I have a TP mesh and a FP Mesh, each has separate weapon mesh and have to be attached to their hand bone.

I have this code :

FirstPWeapon->AttachToComponent(GetMesh(),
FAttachmentTransformRules::SnapToTargetIncludingScale,
FName(TEXT("hand_r")));
    
ThirdPWeapon= FirstPWeapon;
ThirdPWeapon->AttachToComponent(CharacterTPMesh,
FAttachmentTransformRules::SnapToTargetIncludingScale,
FName(TEXT("hand_r")));

As you can see I’m trying to copy “FirstPWeapon” into “ThirdPWeapon”, but when ever i do that i end up moving the “FirstPWeapon” into “ThirdPWeapon” and that makes “FirstPWeapon” empty.

  • how can i have another copy of FirstPWeapon?

You not coping at all and operating on single object. Keep in mind FirstPWeapon and ThirdPWeapon variables are only pointers (because this is only way you can reference a UObject in variable), pointers is works like integer variable containing memory address to the object it points to so when you do ThirdPWeapon= FirstPWeapon you just set ThirdPWeapon to point to same object as FirstPWeapon and both pointers now point to the same object.

You should operate components using there functions as well of component related function inside the actor. I don’t know the rest of the code but you need to have 2 sperate components for FirstPWeapon and ThirdPWeapon and activate them and deactivate them using function in component for example when needed