[Bug] Networking: AttachToComponent generates offset on client

I have a reload animation montage that has several AnimMontage events.
Two of them are to attach the magazine to the characters hand:
The first when removing the magazine from the gun and the second when the new magazine is spawned at the back.

The bug is, that when playing on a dedicated server (PlayerCount = 1+, DedicatedServer = checked), the magazine has a huge offset (10 - 50 units), when attaching it to the hand, when removing the magazine from the gun. This bug is consistent when on a dedicated server, BUT:

  • In singleplayer (PlayerCount = 1; DedicatedServer = unchecked) everything is fine
  • In multiplayer, WITHOUT dedicated server (PlayerCount = 2; DedicatedServer = unchecked) everything is fine, BOTH on the client and the listening server!

I tried two version:

  1. The magazine is attached to the hand and is set to keep world offset
  2. The magazine is snapped to the hand and then the distance between the mag and the hand before snapping as added as a relative offset (SetActorRelativeTransform). This offset is relative small (< 5 units).

In both (!!!) versions I got the huge offset.
When I snap the magazine to the hand, without offset, everything is fine.

Magazine and weapon do NOT replicate movement.

The magazines transforms are different (!!!) between server and client by a huge margin (that difference is the strange offset). There is no good reason why there can be such a huge difference. The character is set to replicate movement and therefore the location must be the same.

The magazine’s location does also not change before and after attaching!!! (See log prints below).

Here is the function for attaching the magazine to the hand:

void AHumanoid::GrabItem(AItemBase* ItemToGrab, bool bKeepRelativeOffset /*= true*/, const FTransform& Offset /*= FTransform()*/)
{
	EAttachmentRule attachmentRule;
	attachmentRule = EAttachmentRule::SnapToTarget;
	FAttachmentTransformRules rules = FAttachmentTransformRules(attachmentRule, false);
	FName handSocket = "HandLeft";

	FTransform AttachOffset = FTransform();
	AttachOffset.SetLocation(GetMesh()->GetSocketTransform(handSocket).InverseTransformPosition(ItemToGrab->GetActorLocation()));
	AttachOffset.SetRotation(GetMesh()->GetSocketTransform(handSocket).InverseTransformRotation(ItemToGrab->GetActorRotation().Quaternion()));

	UE_LOG(LogTemp, Warning, TEXT("[%s] Offset: %s"), HasAuthority() ? *FString("Server") : *FString("Client"), *AttachOffset.GetLocation().ToCompactString());
	UE_LOG(LogTemp, Warning, TEXT("[%s](Before attaching) Mag position: %s"), HasAuthority() ? *FString("Server") : *FString("Client"), *ItemToGrab->GetActorLocation().ToCompactString());
	ItemToGrab->AttachToComponent(GetMesh(), rules, handSocket);
	ItemToGrab->SetActorRelativeTransform(AttachOffset);
	UE_LOG(LogTemp, Warning, TEXT("[%s](After attaching) Mag position: %s"), HasAuthority() ? *FString("Server") : *FString("Client"), *ItemToGrab->GetActorLocation().ToCompactString());
	_ItemInHand = ItemToGrab;
}