Transports and room codes
Sessions (turn-based and real-time) only use a transport that carries datagrams. This chapter covers the layer on top of it that "finds the other player and connects" (detphys_link.h) and the idea of room codes used for matches over the internet.
- DetPhys runs no servers. Room search, NAT traversal and relays belong to the transport you plug in (EOS, Steam, a relay you host yourself).
- Transports never enter the simulation. Different room codes, clocks, addresses or paths (direct or relayed) give the same confirmed tick hashes.
Two layers
| Layer | Header | Contents |
|---|---|---|
| Datagram interface | detphys_ in detphys_turn.h | Two functions, send and recv. Up to 1200 bytes each. Datagrams may be lost, reordered or duplicated (the session resends and reorders) |
| Connection interface | detphys_link.h (version 1) | Create a room, join with a room code, poll every frame, state and reason, counters. Gives you a detphys_ to pass to the session |
Writing your own detphys_ still works. detphys_link lets you write the same steps and the same screens ("create a room", "enter a code", "connected", "the other player left") for every transport.
Usage (the same for every transport)
detphys_link* link = NULL;
/* 1. Create (here the test lobby; for EOS and others only the create call differs) */
detphys_link_create_hub(hub, &link);
/* 2. The host creates a room / the guest joins with a room code */
detphys_link_room_desc room;
detphys_link_room_desc_default(&room);
room.bucket = "mygame/1.2"; /* game and version; only rooms in the same bucket are found */
if (is_host) {
detphys_link_host(link, &room); /* a room code is made (read it from info.room_code) */
} else {
room.code = typed_text; /* the typed text as is (full-width digits and separators are skipped) */
int32_t rc = detphys_link_join(link, &room);
if (rc == DETPHYS_LINK_E_CODE_CHECK) { /* a typo, caught before any traffic */ }
}
/* 3. Poll every frame. Create the session once the role is known */
detphys_link_poll(link);
detphys_link_info info = { sizeof info };
detphys_link_get_info(link, &info);
if (!session && info.role != DETPHYS_LINK_ROLE_UNKNOWN) {
detphys_transport tr;
detphys_link_transport(link, &tr);
cfg.local_peer = info.role; /* host = 0, guest = 1 */
session = detphys_rt_create_push(&cfg, &push, &tr);
}
/* 4. Done: destroy the session, then the link (destroying the link leaves the room) */- Roles: the side that created the room is the host (peer 0, the reference on a desync); the side that joined is the guest (peer 1). The same as the samples today.
- Datagrams sent before the other player is connected are refused with
DETPHYS_. The session sends again later, so you can create the session as soon as the role is known.LINK_ E_ NOT_ READY - Threads: use one
detphys_linkfrom one thread (poll, send and recv on the same thread). SDK callbacks run insidedetphys_.link_ poll
States and reasons
State (DETPHYS_) | Meaning | Example screen |
|---|---|---|
IDLE | Just created (a transport with rooms, before host / join) | "Create a room", "Enter a code" |
OPENING | Logging in, creating, searching, joining, or opening the path to the other player | "Connecting…" |
WAITING | Host: the room exists and waits for the other player. UDP listen: waiting for the first datagram | "Tell the other player the room code 123 456" |
CONNECTED | The other player is known; datagrams flow | Go to the match |
CLOSED | Closed (reason PEER_LEFT = the other player left, CLOSED = you closed it) | "The other player left the room" |
FAILED | Failed (reason below, text from detphys_) | A message per reason |
Reasons (DETPHYS_): NOT_FOUND (no room with that code), FULL, CODE_TAKEN (the code is in use; a code made by the link is remade automatically), PEER_LEFT, CLOSED, TIMEOUT, LOGIN (logging in to EOS or similar failed), NETWORK, BACKEND (anything else; see detphys_). detphys_ and detphys_ return ASCII names ("not_found" and so on) you can use as translation keys. The core's text (detphys_) is meant for developers.
Room codes
- Six digits. The first five are the room number (100,000 rooms); the last is a check digit (the Damm algorithm).
- Every single-digit typo and every swap of two neighboring digits is caught by
detphys_withlink_ join DETPHYS_before any traffic (you never land in a stranger's room). This is checked over all 100,000 prefixes: all 5,400,000 single-digit errors and all 450,000 neighbor swaps. Swaps across one digit (abc → cba) and twin errors (aa → bb) are caught about 90% of the time.LINK_ E_ CODE_ CHECK - Full-width digits, spaces, hyphens and "ー" in the typed text are skipped ("123ー456" and "123 456" are the same). Any other character, or not exactly six digits, gives
DETPHYS_. To only check a code, useLINK_ E_ CODE_ FORMAT detphys_.room_ code_ parse - Show codes on screen in two groups of three ("123 456").
- Rooms are separated by bucket (a game and version name; 1–63 characters of letters, digits and
. _ - / :). Peers on different versions cannot connect anyway (the config check refuses), so putting the version in the bucket hides their rooms from the start. - The host's link makes the code (OS randomness; set
detphys_for a fixed code in tests). To use a code of your own, setlink_ room_ desc. entropy room.code. When a code made by the link is already in use, the link remakes it (up to 8 times;detphys_).link_ info. host_ attempts - Room codes never enter the simulation (they are for connecting only).
Transports that come with DetPhys
| Transport | Create with | Role | Room codes | Use |
|---|---|---|---|---|
| UDP | detphys_ | Chosen at creation | No | LAN and tests. Listen (LISTEN) is WAITING until the first datagram; connect (CONNECT) is CONNECTED from the start |
| Loopback | detphys_ | The side (0 / 1) | No | Two peers in one process, with delay, loss and duplication |
| Test lobby (hub) | detphys_ → detphys_ | Decided by the room | Yes | Create a room → join with a code → connect, inside one process, in the same shape as EOS (no operation finishes at once; they progress in poll). For building screens and for tests |
| Your own relay | detphys_ (detphys_relay.h) | Decided by the room | Yes | Through a detphys_relay on your own server. Over the internet and between peers behind firewalls. See "Your own relay" below |
| EOS P2P | detphys_ (detphys_eos.h, separate library detphys_eos) | Decided by the room | Yes | Over the internet without a server of your own (EOS relay when NAT traversal fails). The EOS SDK comes from Epic. See "EOS P2P" below |
Test lobby settings (detphys_): time per room operation (op_delay, in pumps), a room limit, the path to report (path; to test a relay indicator), the datagram limit (max_packet; to test with the EOS limit) and per-room delay, loss and duplication (packets). Time advances with detphys_.
Measured (PC i7-12700F, 2026-11-11)
- The largest datagram with only inputs and hash checks is 55 B. Resync state chunks are 1051 B (rt) and 1057 B (turn-based) at
chunk_bytes1024. - Push for 1800 ticks and stacking for 120 turns through the test lobby (datagram limit 1170 B, one-way 40–80, 10% loss, 2% duplication): every confirmed tick hash matched the reference. The same on a Galaxy S9.
- The same push over a UDP link and a loopback link gives the same confirmed tick hashes on both transports and both peers.
Writing your own transport (your own server, ...)
Fill a detphys_ and pass it to detphys_. The link (detphys_link) refuses oversized datagrams, counts what was sent and received, checks and normalizes room codes and remakes codes that are in use, so your implementation only carries datagrams and runs the room operations.
| Function | Required? | What it does |
|---|---|---|
send / recv | Yes | Send one (0 = accepted, negative = cannot send) / take one (its size, 0 if none) |
get_info | Yes | Write the state, role, path, reason, round trip (-1 if unknown), descriptions of the other side and yourself, and the room code (the link writes the counters) |
poll | Optional | Every frame. Run the SDK |
host / join | Optional (without them, DETPHYS_) | Create / join a room. The code arrives as six checked digits. They need not finish at once (set OPENING and progress in poll) |
wait, error, close, destroy | Optional | Wait (headless tests), error text, leave the room, clean up |
Rules:
- Set
max_packet(the largest datagram) correctly. The largest thing a session sends is a resync state chunk (chunk_bytes+ a header of about 33 B).chunk_bytesis 64–1100 (default 1024), so keep it at least 40 B below the transport limit. - Carrying datagrams unreliably and unordered is fine (the session fills the gaps). Reliable delivery (TCP, Steam's reliable sends) is not recommended because it adds delay.
- Drop datagrams from anyone who is not in the room (never pass a stranger's packets up).
- Other lobby systems fit the same shape when the room code becomes a lobby attribute or the room name sent to your server (the "Your own relay" and "EOS P2P" sections below are examples).
Your own relay (detphys_relay)
When you use neither EOS nor Steam (you have your own servers, consoles, LAN events, ...), DetPhys comes with a small UDP relay you can put on your own server. DetPhys does not run servers. It ships the relay program and the steps to set it up; you run it.
- Relay:
detphys_relay(one C++ program for Windows / Linux that depends on neither the core nor Box2D). It joins 2 to 15 peers by room code and carries datagrams without looking inside. - Source in the Unity package:
Packages/(the four source files,dev. petaf. detphys/ Tools~/ detphys_ relay/ CMakeLists.txt,Dockerfile, the systemd unit and a README with the build steps). Copy the folder out of the project and build it there. - Link:
detphys_inlink_ create_ relay detphys_relay.h(built into the core DLL / .so; no SDK needed). The steps are the same as for every transport (create →detphys_/link_ host detphys_→link_ join detphys_every frame).link_ poll - The path (
detphys_) islink_ info. path DETPHYS_. The overhead is 1 byte per datagram andLINK_ PATH_ RELAYED max_packetis 1199 B (a 1057 B resync chunk fits). - The results (confirmed tick hashes) are the same through the relay. The relay never changes the contents.
On the game side
detphys_relay_desc rd;
detphys_relay_desc_default(&rd);
rd.host = "relay.example.com"; /* a name or an IP address (IPv4 / IPv6) */
rd.port = 40400; /* 0 = the default 40400 */
detphys_link* link = NULL;
detphys_link_create_relay(&rd, &link); /* no network traffic yet */
/* then the same as "Usage": detphys_link_host / detphys_link_join → detphys_link_poll every frame → create the session once the role is known */- The name is resolved (DNS) once, inside the first
detphys_/link_ host detphys_(it blocks while it waits; call it when the player presses "create room" / "join"). If it cannot be resolved the link becomeslink_ join FAILED(reasonNETWORK). - The round trip to the relay is
detphys_(a PING every second). The round trip to the other peer is in the session'slink_ info. rtt_ ms detphys_.rt_ get_ link_ info - Reasons:
NOT_FOUND(no such room),FULL,CODE_TAKEN(the link remakes codes it generated),TIMEOUT(no answer from the relay / nothing for 10 seconds),PEER_LEFT(the other peer left; when the host leaves the room closes),NETWORK(name resolution, sockets),BACKEND(relay limits, version mismatch;detphys_explains).link_ error - Settings (
detphys_):relay_ desc local_port(fix your own port; normally 0),hello_(resend interval for room operations, default 250),interval_ ms ping_interval_ms(default 1000),silence_(default 10000).timeout_ ms - Browsers (wasm) cannot send UDP, so web games cannot reach this relay directly (that needs a separate WebSocket / WebRTC layer, which does not exist yet).
Setting up the relay
Any server where you can open one UDP port works (a cheap VPS with 1 vCPU and 512 MB is enough). A room uses about 31 kbit/s, so bandwidth and monthly transfer decide how many rooms you can host (see "Measured" below).
First copy the relay's source folder out of the project (Unity: Packages/, for example to ~/detphys_relay) and run the commands below in that folder. Its README.md has the same steps.
Docker (Linux): in the copied folder
docker build -t detphys-relay .
docker run -d --name detphys-relay --restart unless-stopped -p 40400:40400/udp detphys-relay
docker logs -f detphys-relay # rooms opening and closing, counters every 5 minutes- The image copies only the relay's four source files. The relay runs as nobody, not root.
- To change settings, put options after the image name (
docker run ... detphys-relay --port 40400 --max-rooms 200). - With many rooms,
--network hostis lighter because traffic skips Docker's NAT.
Without Docker (Linux): one g++ command builds it (C++17, standard library only).
g++ -std=c++17 -O2 -pthread -I . relay_main.cpp relay_server.cpp -o detphys_relay
sudo cp detphys_relay /usr/local/bin/ && sudo cp detphys-relay.service /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now detphys-relayWindows (Visual Studio 2019 or newer): in the copied folder, cmake -S . -B build and cmake --build build --config Release produce build\Release\detphys_ (CMake also works on Linux). To accept traffic from outside, allow inbound UDP on the port in Windows Firewall (in an administrator PowerShell: New-NetFirewallRule -DisplayName "DetPhys relay" -Direction Inbound -Protocol UDP -LocalPort 40400 -Action Allow).
Wherever you put it:
- Open inbound UDP 40400 on the server (the VPS panel's firewall / security group,
ufw, ...). - Decide the name the game uses (
rd.host). An IP address works, but a DNS name (A / AAAA) lets you move the server later. - Change the bucket (game and version name) for every version, so players never see rooms from other versions.
- After starting it, connect two devices and check that the log shows
room-openandroom-close ... out_.Bps=...
Relay options
| Option | Default | Meaning |
|---|---|---|
--bind | :: | Address to listen on. :: means both IPv6 and IPv4 (falls back to 0.0.0.0 automatically where IPv6 is unavailable) |
--port | 40400 | UDP port (0 = the OS picks; written to --port-file) |
--max-rooms | 1000 | Maximum number of rooms |
--max-rooms-per-ip | 16 | Rooms one IP address may create (0 = no limit) |
--max-peers | 8 | Maximum peers per room (2–15; the DetPhys link uses 2 for now) |
--room-kib-per-s / --room-burst-kib | 256 / 512 | Rate one room may carry [KiB/s] and its burst. Anything above is dropped (the push sample needs about 4 KiB/s, a 60× margin) |
--hello-per-s | 10 | Rate of room operations (create / join) from one IP. Above it the relay does not answer |
--peer-timeout-ms | 10000 | A peer that sends nothing for this long has left (the link sends a PING every second) |
--max-room-s | 0 | Maximum lifetime of a room [s] (0 = none) |
--stats-s | 60 | Interval of the counter line [s] (0 = never) |
--verbose | – | Also log addresses when peers come and go (off by default) |
Log (standard output, one event per line): relay-listen ... (started), room-open id= bucket= code=, room-close ... why= secs= out_ (bandwidth per room), stats rooms= peers= ... dropped=unknown:,rate:,bad: fwd_, final ... (when it stops on Ctrl+C / SIGTERM).
Abuse limits and rules
- The relay carries data only from addresses that joined a room, and only to the others in that room (data from unknown addresses is dropped). The link connects its socket to the relay, so it accepts packets from nobody else.
- Room operations (create / join) are padded to 96 B and the relay's answers are smaller (a request with a forged source address cannot make the relay send something bigger to a victim: no amplification). PING and PONG are the same size.
- When an address changes (mobile networks, a NAT changing ports) the next PING (within a second) rebinds it by its token. Data in between is lost and the session resends it.
- Room codes have 100,000 values, so a stranger may guess one (a room full with two players cannot be joined). Games that need a password should add their own value to the session's configuration check (tag).
- Times, addresses and room codes never enter the simulation (the hashes are the same through the relay).
Protocol (for writing your own client)
Everything is in relay_protocol.h in the relay's source folder (version 1). The first byte is the type: 0xD0 | slot is data (peer → relay: the destination slot, 0xF = everyone; relay → peer: the sender's slot); everything else is a room operation starting with [type]['D']['R'][version] (HOST, JOIN, PING, LEAVE / WELCOME, REJECT, PONG, PEER). Numbers are little endian.
Measured (PC i7-12700F, Galaxy S9 on Wi-Fi, 2026-11-11)
- Added latency: a round trip inside the PC is only about 60 µs longer than direct UDP (about 19 µs inside the relay per pass). PC ↔ S9 (Wi-Fi) round trips were 12–22 ms both direct and through the relay, a difference below the Wi-Fi jitter. With a remote relay the delay is set mostly by the path you → relay → the other peer (expect a few ms to 20 ms one way extra for a VPS in the same country).
- Bandwidth per room (what the relay sends, both directions together): push uses about 31 kbit/s (about 118 datagrams per second, 33 B on average), about 14 MB per hour. Stacking only grows during resyncs (70–130 kbit/s).
- Two processes on one PC and PC ↔ S9 matches (push, moving field, stacking, with injected loss and delay) gave identical confirmed tick hashes on both sides.
- Above the room limit or the per-IP room limit the relay refuses with
BACKEND. Traffic over the bandwidth limit (for example 1 KiB/s) is dropped.
Using it from the engines (Unity, Godot)
The same interface is available from Unity's C# and from Godot (the GDScript GDExtension and C#). The steps are the same for every transport (create -> make / enter a room -> poll every frame -> create the session when the role is known).
Unity (C#, DetPhys namespace):
// The side that makes the room (host = peer 0). The side that enters uses host: false and code (the typed room code)
var room = new DetPhysRoomOpener(() => DetPhysLink.CreateRelay("relay.example.com"), host: true, bucket: "mygame/1.2");
// every frame
if (!room.Ready && room.Poll())
session = DetPhysRtSession.CreatePush(settings, rules, meshes, room.Role, room.Link.Endpoint);
// room.Link.Info.RoomCode (the 6 digits the host shows), Info.Path (DetPhysLinkPath.Relayed ...), Info.RttMs (round trip to the relay)
// During the match keep calling room.Link.Poll() every frame. Dispose the session, then the roomDetPhysRoomOpenerenters again untilretryForMswhen a guest arrives before the host's room exists (NotFound). Handy for tests and automatic runs; when a person types the code, use 0 and show "no such room".- Typos are found before any traffic with
DetPhysRoomCode.(Parse(text, out code) CodeFormat/CodeCheck). - The test lobby (
DetPhysLinkHub) runs the same flow (make a room -> enter by code -> play) inside one process.
Godot (GDScript):
var link := DetPhysLink.relay("relay.example.com") # port 0 = 40400
link.host_room("mygame/1.2") # the side that enters: link.join_room(code, "mygame/1.2")
# every frame link.poll(). When link.get_role() is 0 / 1 (host: WAITING, guest: CONNECTED)
var m := DetPhysRtMatch.new(); add_child(m); m.start(link.get_role(), link) # the node calls link.poll() every frame
print(link.get_room_code(), " ", link.get_info()["path_name"]) # e.g. "529371 RELAYED"DetPhysLinkHub.andcreate(...) hub.give the test lobby.create_ link() DetPhysLink.checks for typos first.room_ code_ check(text) - The steps with entering again are in the sample's
samples/(the same behaviour as Unity'scommon/ detphys_ sample_ room. gd DetPhysRoomOpener). The C# layer hasDetPhysLink.,CreateRelay DetPhysLinkHub,DetPhysRoomCodeandDetPhysRoomOpener(addons/, used as in Unity).detphys/ csharp/ DetPhysLinks. cs
The samples (Unity PushVersus / StackVersus, Godot push_versus / stack_versus) connect over LAN UDP by default. Type host or host:port into "Relay" in the menu and press "Make a room" to get a room code. On the other device, type the same relay and the code and press "Enter the room".
Launch options: relay=<host>[:<port>], room=<room code>, roomseed=<n> (tests: the same n on both sides gives a known room), bucket= (default detphys-sample/, detphys-sample/), localport=.
Measured (Unity 6000.3, Godot 4.7.2 .NET, PC i7-12700F, Galaxy S9 on Wi-Fi, 2026-11-11)
- Through a relay on the PC, Unity ↔ Godot (PC to PC, and PC to S9) played push for 1800 ticks (30–60 ms delay, 10% loss, 2% duplicates on both sides) and stacking for 120 turns, with either side as host. Every confirmed tick hash and every result matched on both sides.
- When the guest arrived before the host's room existed, it entered again and had its role within 2 s.
- In push one side sent about 57 KB to the relay in 30 s (33 B per tick).
Using it from Unreal
The Unreal layer (plugin DetPhys) wraps the same interface, callable from Blueprint and C++.
- Steps:
UDetPhysLink::CreateRelay(Outer, Host, Port, LocalPort)->HostRoomorJoinRoom->Pollevery frame -> onceGetRole()is 0 / 1, use it as the LocalPeer and give the link to a session (UDetPhysRtSession::CreatePushand so on). - Read the state with
GetInfo()(FDetPhysLinkInfo) andGetLinkError().RoomCodeCheck(Text)catches typos before any traffic. UDetPhysRoomOpener::OpenRelayRoom(...)(OpenHubRoomfor the test lobbyUDetPhysLinkHub) holds the steps with entering again (the same as Unity'sDetPhysRoomOpener).- The shortest way is a match component. Add
UDetPhysRtMatchComponent(UDetPhysStackMatchComponentfor stacking) to an Actor and callHost Relay Room/Join Relay Room. The component creates the session once the role is known, steps it in Tick and reports through Delegates such asOn ConnectedandOn Tick Confirmed.
// C++ (the same nodes in Blueprint)
UDetPhysRtMatchComponent* M = ...; // attached to an Actor; Shapes, Settings and Rules the same on both peers
M->RoomBucket = TEXT("mygame/1.2");
M->HostRelayRoom(TEXT("relay.example.com"), 0, TEXT("")); // the side that enters: M->JoinRelayRoom(TEXT("relay.example.com"), 0, Code)
M->OnRoomReady.AddDynamic(this, &AMyActor::HandleRoomReady); // (Role, RoomCode, Link); the host shows RoomCode
M->OnTickConfirmed.AddDynamic(this, &AMyActor::HandleTick); // (Tick, Hash, Flags); the same Hash on both peers
// every frame M->LocalInput = UDetPhysLibrary::MakePushInput(Move, bJump, bDash);- Samples: the push maps
PushVersusandPushComponents(built only with the components) and the commandlet-run=DetPhysVersus(stacking too) take the launch optionsrelay=,room=,roomseed=,bucket=,localport=the same way as Unity and Godot.
Measured (UE 5.8.4, Unity 6000.3, Godot 4.7.2 .NET, PC i7-12700F, 2026-11-11)
- Through a relay on the PC, Unreal ↔ Unity and Unreal ↔ Godot played push for 1800 ticks (30–60 ms delay, 10% loss, 2% duplicates on both sides) and stacking for 120 turns, with either side as host (both the commandlet and the map built with components). Every confirmed tick hash and every result matched on both sides.
- From opening the room to the role: 1–3 ms in the commandlet, about 0.5 s in the map (stepped in Tick).
- The plugin's automation test
DetPhys.(room codes, the test lobby, relay time-out, two components playing each other) runs from Session Frontend > Automation.Sample. Link
EOS P2P
Epic Online Services P2P (free; NAT traversal and a relay when traversal fails are on the EOS side) goes on this interface. You need no server of your own. In this version it works on Windows and Android in Unity and Godot, and on Windows in Unreal.
- Terms and cost: EOS is free to use. You need an Epic Developer Portal account, the EOS SDK from Epic and your acceptance of Epic's terms for EOS. EOS is optional: everything else in DetPhys works without it.
- The EOS SDK is not bundled. Get it from the Epic Developer Portal. DetPhys is not affiliated with or endorsed by Epic Games.
- Values to create in the portal (they ship with your game): Product ID, Sandbox ID, Deployment ID, Client ID and Client Secret. EOS client credentials for game clients are meant to be in the client, so use a client policy that allows only P2P and Lobby (Peer2Peer). Keep the values out of version control. Login uses a device ID, so players need no Epic account.
- How to use it: fill the defaults with
detphys_fromeos_ desc_ default detphys_eos.h(a separate library,detphys_eos), put in the portal values and create the transport withdetphys_. The rest is the same as any transport: the host callseos_ link_ create detphys_, the guestlink_ host detphys_, and you calllink_ join detphys_every frame. When creation fails,link_ poll detphys_explains why; calleos_ last_ error detphys_once at the end of the process.eos_ shutdown - One login per process: the first transport initializes EOS and logs in with a device ID (it advances inside poll, so you can call host / join without waiting for it). The login survives destroying the transport, so the next one goes straight to the room operation. One transport at a time per process.
- How it connects: the host creates an EOS Lobby (two members; bucket = the Lobby's BucketId, room code = a Lobby attribute); the guest searches the same bucket and room code and joins. The guest asks for the P2P path and the host accepts it. When NAT traversal fails it falls back to the EOS relay.
detphys_is the path as seen from your side; if either side reportslink_ info. path DETPHYS_, the EOS relay is in between. The result (the hash) is the same over the relay.LINK_ PATH_ RELAYED - A room that was just created can take a moment to appear in search. If the guest gets
NOT_FOUND, wait a little (about 0.5 s), create the transport again and retry the join (the login is kept, so it is quick). - One datagram is at most 1170 bytes (the EOS limit;
detphys_). The largest datagram a DetPhys session sends is a resync state chunk of about 1060 bytes, so it fits.link_ info. max_ packet - Relay control (
detphys_):eos_ desc. relay DETPHYS_(default; relay only when a direct path fails),EOS_ RELAY_ ALLOW DETPHYS_(always relay; to test the relayed case),EOS_ RELAY_ FORCE DETPHYS_(never relay; fails withEOS_ RELAY_ NEVER NETWORKif no direct path). - Two players on one machine: the device ID is one per device and OS user, so two processes on the same PC become the same EOS user and cannot connect (the guest fails with
LOGIN). SetDETPHYS_inEOS_ FLAG_ NEW_ DEVICE_ ID flagsfor the second process only; it recreates the device ID and becomes another user. Do not use it in a game (players would become a new user every time). - Android: the EOS SDK needs its Java side set up first. Before creating the transport, call
System.andloadLibrary("EOSSDK") com.from your Activity (otherwise creation fails withepicgames. mobile. eossdk. EOSSDK. init(activity) BACKENDand the message saysEOS_). Add the EOS SDK aar (Android_ JavaVMNotStored eossdk-StaticSTDC-release.) and the AndroidX libraries it uses (aar androidx.browser,androidx.core,androidx.) with Gradle, and thesecurity:security-crypto INTERNETandACCESS_permissions. You can passNETWORK_ STATE Context.or similar asgetFilesDir() cache_dir. - iOS: not available in this version (in Unity and Godot,
DetPhysEos.is false on iOS).IsAvailable - Where the SDK goes (when you build the core yourself): put the
SDKfolder from Epic's zip atsdk/eos/SDK(so thatsdk/exists) and unpack the Android and iOS zips over the sameeos/ SDK/ Include/ eos_ sdk. h SDKfolder (for Android,libEOSSDK.sois taken out of the aar and linked). CMake'sDETPHYS_EOSisAUTOby default (built when the SDK is found, left out otherwise). Set it toONto require it (configure stops without the SDK). For another place pass-DDETPHYS_. On Windows build with MSVC or clang-cl for x64.EOS_ SDK_ DIR=<SDK folder>
Using it from Unity and Godot
The EOS transport is a DetPhysLink like the others (make / enter a room, poll every frame, create the session when the role is known). Only creating it is different.
1. Put the EOS SDK's files in your project (they are not in the DetPhys package or addon; take them from your EOS SDK)
| Unity | Godot | |
|---|---|---|
| Windows | EOSSDK-Win64-Shipping. under Assets (for example Assets/) | EOSSDK-Win64-Shipping. in addons/ (next to the executable in an exported game) |
| Android | eossdk-StaticSTDC-release. under Assets/ | eossdk-StaticSTDC-release. in addons/. Export with the Gradle build |
- DetPhys adds the Android Gradle settings: the AndroidX libraries the aar uses (
androidx.,appcompat androidx.browser,androidx.) and core library desugaring, which the aar requires (security:security-crypto coreLibraryDesugaringEnabledandcom.). In Unity the package's Editor script adds them when the Gradle project is generated; in Godot the editor plugin adds them when you export (it appends them once to the end ofandroid. tools:desugar_ jdk_ libs res://, marked withandroid/ build/ build. gradle // DetPhys:). Projects without the aar are not changed. - The Java-side setup on Android (
EOSSDK.init) is done by a small DetPhys helper (detphys-eos-android., included in the package and the addon). It is called automatically when the first transport is created.aar - When EOS cannot be used (the files are missing), the other transports keep working. Check with
DetPhysEos.in Unity and Godot C#, andIsAvailable DetPhysLink.in Godot GDScript.eos_ available()
2. Pass the portal values: build the settings in code or read them from an ini file ([eos] with ProductName, ProductVersion, ProductId, SandboxId, DeploymentId, ClientId, ClientSecret). DetPhys contains no EOS values: the settings come only from your code or your ini file. Keep the ini file and the client secret out of version control (they ship with your game; see EOS P2P).
Unity (C#):
var settings = DetPhysEosSettings.Load(DetPhysEosSettings.Find()); // or new DetPhysEosSettings { ProductId = ..., ... }
var room = new DetPhysRoomOpener(() => DetPhysEos.CreateLink(settings), host: true, bucket: "mygame/1.2",
retryForMs: 0, retryEveryMs: 1000); // the joining side: host: false and the code
// Call room.Poll() every frame. When room.Ready, create the session with room.Role and room.Link.Endpoint (the same as the relay)DetPhysEosSettings.looks forFind() detphys_eos.iniinApplication.(on Android, the app's external files folder) and in the executable's folder.persistentDataPath - In the Editor (Windows), the
EOSSDK-Win64-Shipping.underdll Assetsis loaded before the first call. - The match components (
Connection: Eos) read the same file: the path inEos Config(a file or the folder that has it), or the places above when it is empty.
Godot (GDScript):
const DetPhysEos := preload("res://addons/detphys/eos/detphys_eos.gd")
var settings := DetPhysEos.load_ini(DetPhysEos.find_ini()) # or build {"product_id": ..., "client_secret": ...} yourself
var link := DetPhysEos.create_link(settings) # null: see DetPhysEos.error()
link.host_room("mygame/1.2") # the joining side: link.join_room(code, "mygame/1.2")
# Call link.poll() every frame. When the role is known, give the link to DetPhysRtMatch and so on (the same as the relay)find_ini()looks fordetphys_eos.iniinuser://, the app's external files folder on Android and the executable's folder. The settings keys areproduct_id,sandbox_id,deployment_id,client_id,client_secret,product_name,product_version,relay("allow"/"force"/"never"),display_name,cache_dirandlog_level.- You can also call the GDExtension's
DetPhysLink.directly (prepare Android witheos(settings) DetPhysEos.).prepare_ android()
Godot (C#, addons/): the same names as in Unity.
var settings = DetPhysEosSettings.Load(DetPhysEosSettings.Find()); // res:// and user:// paths work too
var room = new DetPhysRoomOpener(() => DetPhysEos.CreateLink(settings), host: true, bucket: "mygame/1.2");
// call room.Poll() every frame; when room.Ready, make the session with room.Role and room.Link.TransportDetPhysEosSettings.looks forFind() detphys_eos.iniinuser://, the app's external files folder on Android and the executable's folder.CreateLinkprepares the Java side on Android (with the same helper as GDScript).- GDScript and C# use the same
detphys_eos. One EOS transport at a time per process.
3. Samples: the menus of Push, Stacking duel, 3D push and Gear arena have "Make a room (EOS)" and "Enter the room (EOS)" (the room code field is the same as for the relay; Gear arena also has "Make a room (relay)" and "Enter the room (relay)"). Put detphys_eos.ini in the executable's folder on PC, and in the app's external files folder (/) on Android. Launch options: eos=<path of the ini, a folder that has it, or 1> (1 = look in the usual places), eosrelay=allow|force|never, and room=, roomseed=, bucket= as for the relay. A guest that arrives before the host's room exists enters again every second for up to 60 seconds.
Using it from Unreal
The EOS transport is a UDetPhysLink like the other transports (make or enter a room → Poll every frame → start the session when the role is decided). Only the way you create it is different.
- This is not the EOS that comes with Unreal. It does not use Unreal's Online Subsystem EOS or EOS Shared plugins; DetPhys's
detphys_eoscalls the EOS SDK directly. If those plugins also initialize EOS in the same game, the EOS SDK's DLL is loaded from two places and does not work correctly. Do not enable them when you use DetPhys's EOS transport. - Files: put
EOSSDK-Win64-Shipping.(fromdll SDK/Binof your EOS SDK) in your project'sBinaries/Win64folder (in a packaged game, next to the executable). DetPhys's EOS part (detphys_eos.dll) is in the plugin. Without the EOS SDK's DLL, the other transports work as before.UDetPhysEos::IsEosAvailable()tells whether EOS can be used, andGetEosError()tells why not. - Platforms: Windows x64 only in this version (on Android and iOS,
IsEosAvailable()returns false). - Portal values: fill in
FDetPhysEosSettings, or read them from an ini file (ProductName,ProductVersion,ProductId,SandboxId,DeploymentId,ClientIdandClientSecretin[eos]) withLoadEosSettings.FindEosSettingsFilelooks fordetphys_eos.iniin the project'sSavedfolder, the project folder and the folder of the executable.ClientSecretis never saved with an asset or a map (Transient): read it from the ini file at run time, or set it in code. Do not put the client secret in version control. - One EOS transport at a time.
UDetPhysLink::Closefrees an EOS transport at once, so you can create the next one right away (the lastGetInfoandGetLinkErrorstay readable).UDetPhysRoomOpeneralso closes the old one before it tries again.
// C++ (the same nodes in Blueprint)
FDetPhysEosSettings Eos;
UDetPhysEos::LoadEosSettings(UDetPhysEos::FindEosSettingsFile(TEXT(""), {}), Eos); // or fill in Eos.ProductId = ... yourself
UDetPhysRtMatchComponent* M = ...; // the one on your Actor
M->RoomBucket = TEXT("mygame/1.2");
M->StartRoom(UDetPhysEos::OpenEosRoom(M, Eos, /*bHost*/ true, TEXT(""), M->RoomBucket)); // the other side: bHost = false and the Code
M->OnRoomReady.AddDynamic(this, &AMyActor::HandleRoomReady); // (Role, RoomCode, Link). The host shows RoomCode on the screenUDetPhysEos::OpenEosRoommakes a guest that comes before the host try again every second for up to 60 seconds (change it withRetryForMsandRetryEveryMs). To create the session yourself, make the link withUDetPhysEos::CreateEosLink(Outer, Settings)and callHostRoom/JoinRoom.- To shut EOS down at the end, close every EOS transport and then call
UDetPhysEos::ShutdownEos()once (after that, the process cannot use EOS again). - Samples: "Push", "Push, built with components" and "3D push" in the menu have "Make a room (EOS)" and "Enter the room (EOS)" (the room code field is shared with the relay). Put
detphys_eos.iniin the project'sSavedfolder or the project folder. The launch options are the same as in Unity and Godot:eos=<path of the ini, its folder, or 1>,eosrelay=allow|force|never,room=,roomseed=andbucket=. The-run=DetPhysVersuscommandlet also supports them for stacking.
Measured (UE 5.8.4, EOS SDK 1.19.2.1; Unreal headless on a PC i7-12700F / Windows 11, Godot 4.7.2 and Unity 6000.3 on a Galaxy S9 / Android 10 on Wi-Fi; 2026-11-12):
- Unreal ↔ Godot (push, push with Godot as the host, 3D push, stacking, push built with components) and Unreal ↔ Unity (push, 3D push): every confirmed tick hash and every match result was the same (push for 1800 ticks with a 30–60 ms delay, 10% loss and 2% duplicates on both sides; 3D push for 1800 ticks; stacking for 120 turns). Every path was direct.
- From making the room to the role (login included) took 2.6–6.6 seconds, with no retries. Push sent 34–48 B per tick (including the injected duplicates) and 3D push about 33 B. Unreal's core time per frame was 0.14–0.15 ms on average.
Measurements (EOS SDK 1.19.2.1, PC i7-12700F / Windows 11, Galaxy S9 / Android 10, 2026-11-12)
- The push match (with a moving stage) for 1800 ticks and the stacking match for 120 turns ran on every pair below. The confirmed-tick hashes matched the reference on every row and the two processes had identical confirmed ticks (0 desyncs). The same held with injected delay and loss and a forced resync in the middle (1051–1057 B datagrams went through), and with the S9 as the host.
| Pair | Path | Round trip avg (min) [ms] | B/tick (push) | Frame avg [ms] |
|---|---|---|---|---|
| Two processes on one PC | direct | 19–28 (10–14) | 32–33 | 0.3–0.9 |
| Two processes on one PC | relay (FORCE) | 31–34 (26–29) | 33 | 0.4–0.5 |
| PC ↔ S9 (same Wi-Fi) | direct | 29–35 (14–16) | 33 | PC 0.3–0.4, S9 2.2–3.3 |
| PC ↔ S9 (same Wi-Fi) | relay (FORCE) | 40 (20–22) | 33–34 | PC 0.3, S9 3.1 |
| PC (home line) ↔ S9 (LTE) | direct / relayed on one side | 53–59 (45–50) | 33 | PC 0.4, S9 2.2–3.0 |
| PC (home line) ↔ S9 (LTE) | relay (FORCE) | 60 (49–51) | 34 | PC 0.3, S9 3.3 |
- For comparison, plain UDP under the same conditions was 1 ms inside the PC and 11 ms between the PC and the S9 on the same Wi-Fi. EOS P2P adds about 18 ms to the round trip even inside one PC (the send path inside EOS). With 0 input delay a longer round trip means more rollbacks (on these pairs 2–4 per second, with under 0.1 ticks resimulated per frame on average).
- The amount sent is the same as plain UDP (32–34 B per tick for the push match).
- Creating a room (including the login) took 2.5–6 s, and the guest was connected over P2P after 4–16 s (including the first login and retrying until the room appeared in search).
Steam (planned)
A Steam transport (Steam Networking Messages and Steam lobbies) is not included in this version. To play over Steam now, write your own transport on detphys_ with Steamworks Networking Messages (see "Writing your own transport" above), or use EOS P2P or your own relay. DetPhys is not affiliated with or endorsed by Valve.