Download

Server doesn't immediately update character movements from autonomous proxy?

I’m very new to multiplayer programming, so I apologize if I’ve made some dumb mistake here, but it’s the only way I’ll learn. I’m working on a multiplayer game where players can enter and exit vehicles, and so far I’ve got vehicle entering working properly. I’ve hit a slight hiccup with vehicle exiting though. When a player exits the vehicle and tries to move, the server takes a moment to start accepting the player’s movements again. If you look at the gif, you can see that right when the player exits the vehicle he can start running, but on other clients (and the server) the player is motionless for a second before the server realizes that the player is trying to move. The server then teleports the player back to where it thinks he is and allows him to continue moving.

Here are the relevant snippets of code:


void UPassengerComponent::OnInteract(AActor* Instigator)
{
    if (!Instigator)
    {
        UE_LOG(LogTemp, Error, TEXT("OnInteract called on %s with null Instigator!"), *(GetName()));
        return;
    }

    ABaseCharacter* InstigatorCharacter = Cast<ABaseCharacter>(Instigator);
    if (!InstigatorCharacter)
    {
        UE_LOG(LogTemp, Error, TEXT("Instigator on %s is not of type ABaseCharacter!"), *(GetName()));
        return;
    }

    if (!GetOperator()) // Get in
    {
        if (!GetOwnerMesh())
        {
            UE_LOG(LogTemp, Error, TEXT("RootComponent of %s's owner is not of type USkeletalMesh!"), *(GetName()));
            return;
        }

        SetOperator(InstigatorCharacter);
        InstigatorCharacter->SetCurrentBoardable(this);
        GetOperator()->GetMovementComponent()->Deactivate();
        GetOperator()->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
        GetOperator()->AttachToComponent(GetOwnerMesh(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), GetBoardableSocketName());
        MulticastOnEnter(GetOperator());
    }
    else if (GetOperator() == Instigator) // Get out
    {
        GetOperator()->DetachFromActor(FDetachmentTransformRules(EDetachmentRule::KeepWorld, EDetachmentRule::KeepRelative, EDetachmentRule::KeepWorld, true));
        GetOperator()->SetActorLocation(GetComponentLocation() + RelativeExitLocation);
        GetOperator()->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
        GetOperator()->GetMovementComponent()->Activate();
        MulticastOnExit(GetOperator());
        InstigatorCharacter->SetCurrentBoardable(nullptr);
        SetOperator(nullptr);
    }
}

void UPassengerComponent::MulticastOnEnter_Implementation(ABaseCharacter* LocalOperator)
{
    LocalOperator->SetCurrentBoardable(this);
    LocalOperator->GetMovementComponent()->Deactivate();
    LocalOperator->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}

void UPassengerComponent::MulticastOnExit_Implementation(ABaseCharacter* LocalOperator)
{
    LocalOperator->SetActorLocation(GetComponentLocation() + RelativeExitLocation);
    LocalOperator->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
    LocalOperator->GetMovementComponent()->Activate();
    LocalOperator->SetCurrentBoardable(nullptr);
}

Thank you so much in advance! I’m exciting to learn more about UE4 multiplayer through your answers!