Cubic Interpolation Unusable With Unordered Network Packages (UE 4.25)

Hello everybody,

I’m in the last lectures of the Unreal Multiplayer C++ course and was experiencing some quite odd behavior that became visible once I added cubic interpolation. My kart didn’t seem to interpolate nicely but instead flickered around from left to right. The first thing that came to my mind was that this is clearly a bug on my side. So I went through my commits to find out at what point I may have introduced the bug. I went back and forth in the lectures to see if I missed something only to find out that I didn’t.

At the end I downloaded the final course project and applied my network settings to see if I was experiencing the same behavior. Sadly that was the case. The problem comes from my network settings. Because I always appended the following section in my DefaultEngine.ini to avoid setting the network lag all the time through the console.

[PacketSimulationSettings]
PktLag=1000
PktLagVariance=500
PktLoss=10
PktOrder=1
PktDup=10

The line that causes the issue is PktOrder=1 which enables packages to be send without any specific order. Without this setting my code - and the one from the course - works flawlessly. But from what I understand this is actually quite common in large infrastructures. So while it may not cause big issues on a local network it will be almost unplayable over the internet.

What I would now like to know is, if my assumption is correct or if this is something that Unreal can somehow handle internally and I shouldn’t care too much about. And If my assumption is correct, is it possible to make cubic interpolation at least somewhat work?

I already tried using the ServerState.LastMove.Timestamp to check if an incoming ServerState is older than the previously applied one but surprisingly OnRep_ServerState is always called with the ServerState object in correct order (accordingly to the Timestamp).

if (PreviousServerStateTimestamp >= ServerState.LastMove.Timestamp) return;
PreviousServerStateTimestamp = ServerState.LastMove.Timestamp;

Nevermind, I figured it out. It had nothing to do with OnRep_ServerState.

PktOrder and additionally PktDup where triggering those extreme interpolations. To get rid of the interpolation issues just check in ServerSendMove_Validate if the timestamp of a package is older or equal to the currently applied one and set a flag. Then use the flag in the ServerSendMove_Implementation function to decide whether or not to update the server state.

Below is my code with some additional comments in case somebody also wants to handle network issues in their game.

bool UGoKartReplicationComponent::ServerSendMove_Validate(const FGoKartMove& Move)
{
    // check if the arrived package is either a duplicate (equal timestamps = .0f) or if the incoming
    // value is older then the already applied one due to unordered arrival (negative float)
    bReceivedInvalidState = Move.Timestamp - ServerState.LastMove.Timestamp < SMALL_NUMBER;
    // Return true as it is a network error and not a cheat attempt!
    if (bReceivedInvalidState) return true;

    // ...
}

void UGoKartReplicationComponent::ServerSendMove_Implementation(const FGoKartMove& Move)
{
    // Don't simulate anything if we received a duplicate or older package
    if (!MovementComponent || bReceivedInvalidState) return;
    MovementComponent->SimulateMove(Move);
    UpdateServerState(Move);
}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms