When a Relay Beats a Direct Connection: How Our Unreal P2P Plugin Picks the Path

Two players in an AccelByte Gaming Services (AGS) P2P match, one in Jakarta and one in Manila. Their direct route is quick, about 60 ms, but it crosses a congested link that drops packets. A relay server in Singapore would give them about 75 ms with no loss. Standard ICE picks the direct path anyway, because direct always outranks relay. The ping looks better. The match rubber-bands from the first second.
"Direct" only means there's no relay server in the middle. The packets still follow whatever route the two home internet providers choose. We kept seeing this pattern while investigating poor P2P matches: a slow, lossy direct path, where the good matches had connected through a relay. So we dug in.
The result is latency- and loss-aware path selection in the AccelByte Network Utilities plugin for Unreal Engine. It measures every working path before it chooses one. It runs in your game client, it's off by default, and you turn it on with one config line.
Why ICE Chose the Slower Path
In Unreal, AGS P2P connects players through the Network Utilities plugin, which uses ICE (Interactive Connectivity Establishment) through the open-source libjuice library. ICE collects candidate addresses for each player, pairs them up, and checks which pairs can reach each other.
Standard ICE ranks each candidate by its type, not by how well it performs:
Once a higher-ranked pair answers, the controlling side (the player that makes the final choice) stops testing lower-ranked pairs. Relay sits at the bottom, so it often never got checked at all.
That rule assumes a direct path always beats a relay. Usually it does. But a direct route between two home networks can cross a congested or badly peered link, while a relay in a well-connected data center can be faster and cleaner. ICE had no way to tell, because it never measured either path.
Measuring Before Choosing
We changed the selection step so ICE measures every working path before it commits to one. The change lives in our libjuice fork and stays off until you turn it on.
- Keep checking every pair. A direct pair answering first no longer stops the checks on lower-ranked pairs, so the relay pair gets measured too.
- Open a short measurement window. When the first pair succeeds, a measurement window of at least 600 ms opens (configurable). It stays open until every working pair has 12 answered or timed-out probes, for at most 2.4 seconds more. That gives slower pairs, usually the relay, time to report in.
- Probe each working pair. Every 100 ms, each successful pair sends a fresh STUN probe. Each reply updates that pair's round-trip time (RTT). A probe with no reply within twice that RTT (at least 200 ms) counts as lost.
- Choose by measured quality. When the window closes, the pair with the best score is nominated, whatever its type. The choice then stays fixed.
Players don't wait for this. The connection is up as soon as the first pair works. Traffic moves to the chosen pair when the decision comes: usually 1.5 to 2 seconds later, and at most 3 seconds with the default window.
One Score for Latency and Loss
The first version picked the path with the lowest RTT. That would still pick the direct path here, because 60 ms beats 75 ms. But in a real-time game, packet loss often hurts more than extra milliseconds. So we combined both into one number, the effective RTT:
effective RTT = smoothed RTT + (loss % × 10 ms) + (15 ms if relay)
- Smoothed RTT is an exponentially weighted moving average: each new probe counts for a quarter, so one slow reply can't swing the result.
- Loss adds 10 ms per lost percent. Each path is judged on at least 12 probes, so one lost probe adds at most 80 ms (8%).
- The relay bias adds 15 ms to relay paths. A relay adds a hop, so it must win clearly. The margin also stops the choice from flipping on noisy measurements.
In the Jakarta and Manila example, one direct probe gets no reply. The direct path connects first, so by the time the relay has its 12 probes, the direct path has 15. It scores about 120 ms (60 ms plus 60 ms for 6% loss). The relay scores 75 ms, or 90 ms with the relay bias, and wins either way, even though its ping is higher. On a healthy network, where the direct path is fast and clean, direct wins.
Two Traps We Found on the Way
- Retransmitted checks give bad timings. If the first connectivity check was resent, we can't tell which send the reply belongs to. We discard that seed sample and rely on the probes instead.
- "All checks done" can be true too early. Right after the fast direct pair succeeds, there can be no pending pairs, because the slower relay pair hasn't been created yet. Selecting at that moment would lock in direct every time. So the choice waits for the window to close, not for the checks to run out.
How We Tested It
Path selection is hard to test, because the problem only shows on a bad network. We tested from the smallest layer up:
Be clear about what the live sessions show. Every live pairing had a clean connection, so the direct path rightly won each time. The case this feature exists for, a relay beating a slow, lossy direct path, was proven with delay and loss added to real packets to recreate those bad matches: first in the lab, then in a captured session on our office network.
The test-only hooks that inject delay and loss compile only into test builds, never into shipping ones.
We also captured every packet of a real session between two machines on our office network, with an AGS relay server as the other path. With 30% packet loss added to the direct path, about half of its round trips failed while the relay answered nearly every probe, and the plugin chose the relay. With no loss added, it chose the direct path. The animations below replay the captured packets, slowed down four times, with the addresses masked.
Try It
Latency- and loss-aware selection shipped in AGS 2026.5.0 with Network Utilities 5.1.0, for Unreal Engine. Use Network Utilities 5.1.1 (released December 1, 2026) or later: it fixes the choice on paths slower than about 100 ms and on lossy paths. Unity's P2P package doesn't include it yet. It works on AGS Public Cloud and Private Cloud, where AccelByte runs the TURN relays. Relay traffic is included in your AGS subscription at no additional cost (see the TURN relay acceptable use policy). Turn it on in DefaultEngine.ini:
[AccelByteNetworkUtilities]
UseLatencyBasedSelection=True
; Optional. Minimum measuring time. 0 or unset uses 600 ms.
LatencySelectionWindowMs=600To see which path was chosen and how good it is, read the new stats from game code:
FAccelByteNetworkUtilitiesModule& NetUtil =
FAccelByteNetworkUtilitiesModule::Get();
// PeerChannel: the P2P channel for the remote player's connection
FAccelByteP2PConnectionStats Stats;
if (NetUtil.GetConnectionStats(PeerChannel, Stats)
&& Stats.HasMeasurement())
{
UE_LOG(LogTemp, Log, TEXT("P2P path: %d ms RTT, %d%% loss"),
Stats.RttMs, Stats.LossPercent);
}The plugin also logs the final choice as P2P path finalized, with the path type, RTT and loss. To roll back, set UseLatencyBasedSelection=False. For base P2P setup, see Set up P2P transport using OSS.
Current Limits
Network Utilities 5.1.1 fixed the main limits of the first version: replies on paths slower than about 100 ms were counted as lost. A choice made on four or five probes could still pick a lossy path. Two remain:
- A path that connects late. The decision waits for every path that has connected, but not for paths still being checked. A relay that connects only after the decision isn't considered.
- The relay margin. From the deciding player's side, a path through the other player's relay can look like a direct one, so the 15 ms margin doesn't always apply.
What We Learned
- Priority isn't quality. A candidate's type tells you how it reaches the other player, not how well. Measure the path you'll actually use.
- Count loss, not just latency. A low-ping path that drops packets plays worse than a slightly slower clean one.
- Give the slow competitor a fair chance. The relay is always last to report in. Selecting on "everything finished" quietly excluded it.
- Test with real delay. Our first tests added delay to the measurement after a reply had already arrived. That hid a late-reply bug, which only showed up once we delayed real packets.
- Test on a real network too. A packet capture between two machines and an AGS relay showed the choice could still flip after the window closed, which no lab test had shown. Network Utilities 5.1.1 fixes it.
- Ship it behind a flag, with stats. The feature is off by default, rolls back with one config line, and the connection stats show what it chose.
The same applies in games. A ping number on its own can look fine while players rubber-band from packet loss. Show both and players can see what they actually feel.
Try it in your Unreal P2P game and tell us what it picks on Discord. For everything else in the release, read the AGS 2026.5.0 release notes.
Build Multiplayer on AGS
AGS gives your game P2P and dedicated server multiplayer, matchmaking and sessions on one backend, with AccelByte-run relays on Public Cloud and Private Cloud. Start on Public Cloud, or talk to us about Private Cloud.
You're almost signed up!
Verify your account by following the instructions sent to .
If you still haven't received an email, please check your spam folder.

Bring your first player online today.
Get started for free, and scale as your game grows.




