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!
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;
}