Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[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();
     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);
     UE_LOG(LogTemp, Warning, TEXT("[%s](After attaching) Mag position: %s"), HasAuthority() ? *FString("Server") : *FString("Client"), *ItemToGrab->GetActorLocation().ToCompactString());
     _ItemInHand = ItemToGrab;

Product Version: UE 4.20
more ▼

asked Sep 06 '18 at 08:31 PM in C++ Programming

avatar image

186 6 5 13

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question