I am trying to attach a player’s character to a vehicle when entering the vehicle. The code i have works fine when running a local game, but the problem i have is that when running this in a networked game, the character is not being attached to the vehicle.
Below is some code that is called on the server when a player enters a vehicle and when the bIsInVehicle variable is OnRep’d to clients:
SetActorEnableCollision(false);
// Do not allow the character to attempt to walk whilst in the vehicle
GetCharacterMovement()->SetMovementMode(MOVE_None);
GetCharacterMovement()->Deactivate();
// Attach to the vehicle at seat socket
FString SocketName = "Seat_";
SocketName.AppendInt(VehicleSeat);
AttachToComponent(CurrentVehicle->GetMesh(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), FName(*SocketName));
This is only a problem when running a dedicated server.
While debugging this, i made the server log the player’s position while he’s in the vehicle as you can see below:
This suggests the player is either not properly attached or there is some kind of collision or physical happening going on somewhere.
Is there anything i am doing wrong here?