x

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"

C++ AttachToComponent() doesn't weld on simulated proxies?

I'm working on a multiplayer game with vehicles in it, and specifically I've been working on the functionality for players to be able to enter/exit a vehicle. Players can possess the vehicles perfectly, but when I try to attach the players' previous characters to the vehicle I'm having issues on the simulated proxies. When a player tries to enter a vehicle, there is an RPC call to the server so that they can possess the vehicle on the server. The server then sends a multicast RPC to disable collision and attach the character to the vehicle. This works perfectly on the server and the client that owns the player, but on any other clients (clients that do not own the character that is entering the vehicle) the character snaps to place and then falls through the floor. I've attached a .gif that shows the bug. On the client that enters the vehicle (bottom right) and on the server (top left), the character enters the vehicle and stays welded to is as intended. On the other two clients the character falls through as soon as they possess the vehicle and the character does not stay welded to the vehicle. If anybody has any ideas about what I could be doing wrong here it would be greatly appreciated! Thanks so much in advance!

alt text

Here are the relevant snippets of code:

Header File (.h):

     UFUNCTION(NetMulticast, Reliable)
     void MulticastEnterVehicle();
 
     UFUNCTION(Server, Reliable, WithValidation)
     void ServerEnterVehicle();

Implementation File (.cpp):

 void ABaseCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
 {
     ...
     ...
     ...
     PlayerInputComponent->BindAction("EnterVehicle", IE_Pressed, this, &ABaseCharacter::ServerEnterVehicle);
 }
 
 ...
 ...
 ...
 
 void ABaseCharacter::MulticastEnterVehicle_Implementation()
 {
     AttachToComponent(EnterableVehicle->GetRootComponent(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), FName("DriverSeat"));
     GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
 }
 
 void ABaseCharacter::ServerEnterVehicle_Implementation()
 {
     if (Role == ROLE_Authority)
     {
         if (EnterableVehicle)
         {
             EnterableVehicle->SetDriver(this);
             GetController()->Possess(EnterableVehicle);
             MulticastEnterVehicle();
         }
     }
 }
 
 bool ABaseCharacter::ServerEnterVehicle_Validate()
 {
     return true;
 }

Product Version: UE 4.21
Tags:
more ▼

asked Apr 06 '19 at 03:04 AM in C++ Programming

avatar image

NonPolynomialTim
11 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

As mentioned on the forums (copying here for completeness' sake)

The Character Movement code is still running, it doesn't care what the character is attached to. You're disabling collision but gravity is still being applied, so the character will fall through the floor.

In our projects we've found that we've had to make some customizations to the character to not perform movement when attached to something, and to skip replaying moves when attached.

more ▼

answered Apr 08 '19 at 07:25 AM

avatar image

TheJamsh
820 60 97 140

avatar image NonPolynomialTim Apr 10 '19 at 04:07 PM

Disabling the CharacterMovement component on all of the clients fixed the issue:

 GetMovementComponent()->Deactivate();
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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