DetPhysDocs日本語

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

LayerHeaderContents
Datagram interfacedetphys_transport in detphys_turn.hTwo functions, send and recv. Up to 1200 bytes each. Datagrams may be lost, reordered or duplicated (the session resends and reorders)
Connection interfacedetphys_link.h (version 1)Create a room, join with a room code, poll every frame, state and reason, counters. Gives you a detphys_transport to pass to the session

Writing your own detphys_transport 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_LINK_E_NOT_READY. The session sends again later, so you can create the session as soon as the role is known.
  • Threads: use one detphys_link from one thread (poll, send and recv on the same thread). SDK callbacks run inside detphys_link_poll.

States and reasons

State (DETPHYS_LINK_STATE_*)MeaningExample screen
IDLEJust created (a transport with rooms, before host / join)"Create a room", "Enter a code"
OPENINGLogging in, creating, searching, joining, or opening the path to the other player"Connecting…"
WAITINGHost: 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"
CONNECTEDThe other player is known; datagrams flowGo to the match
CLOSEDClosed (reason PEER_LEFT = the other player left, CLOSED = you closed it)"The other player left the room"
FAILEDFailed (reason below, text from detphys_link_error)A message per reason

Reasons (DETPHYS_LINK_REASON_*): 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_link_error). detphys_link_state_name and detphys_link_reason_name return ASCII names ("not_found" and so on) you can use as translation keys. The core's text (detphys_link_error) 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_link_join with DETPHYS_LINK_E_CODE_CHECK 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.
  • 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_LINK_E_CODE_FORMAT. To only check a code, use 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_link_room_desc.entropy for a fixed code in tests). To use a code of your own, set 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

TransportCreate withRoleRoom codesUse
UDPdetphys_link_create_udpChosen at creationNoLAN and tests. Listen (LISTEN) is WAITING until the first datagram; connect (CONNECT) is CONNECTED from the start
Loopbackdetphys_link_create_loopbackThe side (0 / 1)NoTwo peers in one process, with delay, loss and duplication
Test lobby (hub)detphys_link_hub_create → detphys_link_create_hubDecided by the roomYesCreate 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 relaydetphys_link_create_relay (detphys_relay.h)Decided by the roomYesThrough a detphys_relay on your own server. Over the internet and between peers behind firewalls. See "Your own relay" below
EOS P2Pdetphys_eos_link_create (detphys_eos.h, separate library detphys_eos)Decided by the roomYesOver 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_link_hub_desc): 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_link_hub_pump.

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_bytes 1024.
  • 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_link_vtable and pass it to detphys_link_create. 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.

FunctionRequired?What it does
send / recvYesSend one (0 = accepted, negative = cannot send) / take one (its size, 0 if none)
get_infoYesWrite 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)
pollOptionalEvery frame. Run the SDK
host / joinOptional (without them, DETPHYS_LINK_E_UNSUPPORTED)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, destroyOptionalWait (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_bytes is 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/dev.petaf.detphys/Tools~/detphys_relay/ (the four source files, 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_link_create_relay in 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_link_poll every frame).
  • The path (detphys_link_info.path) is DETPHYS_LINK_PATH_RELAYED. The overhead is 1 byte per datagram and max_packet is 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_link_join (it blocks while it waits; call it when the player presses "create room" / "join"). If it cannot be resolved the link becomes FAILED (reason NETWORK).
  • The round trip to the relay is detphys_link_info.rtt_ms (a PING every second). The round trip to the other peer is in the session's 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_link_error explains).
  • Settings (detphys_relay_desc): local_port (fix your own port; normally 0), hello_interval_ms (resend interval for room operations, default 250), ping_interval_ms (default 1000), silence_timeout_ms (default 10000).
  • 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/dev.petaf.detphys/Tools~/detphys_relay, 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 host is 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-relay

Windows (Visual Studio 2019 or newer): in the copied folder, cmake -S . -B build and cmake --build build --config Release produce build\Release\detphys_relay.exe (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:

  1. Open inbound UDP 40400 on the server (the VPS panel's firewall / security group, ufw, ...).
  2. Decide the name the game uses (rd.host). An IP address works, but a DNS name (A / AAAA) lets you move the server later.
  3. Change the bucket (game and version name) for every version, so players never see rooms from other versions.
  4. After starting it, connect two devices and check that the log shows room-open and room-close ... out_Bps=....

Relay options

OptionDefaultMeaning
--bind::Address to listen on. :: means both IPv6 and IPv4 (falls back to 0.0.0.0 automatically where IPv6 is unavailable)
--port40400UDP port (0 = the OS picks; written to --port-file)
--max-rooms1000Maximum number of rooms
--max-rooms-per-ip16Rooms one IP address may create (0 = no limit)
--max-peers8Maximum peers per room (2–15; the DetPhys link uses 2 for now)
--room-kib-per-s / --room-burst-kib256 / 512Rate 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-s10Rate of room operations (create / join) from one IP. Above it the relay does not answer
--peer-timeout-ms10000A peer that sends nothing for this long has left (the link sends a PING every second)
--max-room-s0Maximum lifetime of a room [s] (0 = none)
--stats-s60Interval 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_bytes= out_Bps= dropped_rate= (bandwidth per room), stats rooms= peers= ... dropped=unknown:,rate:,bad: fwd_us=avg:,max:, 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 room
  • DetPhysRoomOpener enters again until retryForMs when 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.create(...) and hub.create_link() give the test lobby. DetPhysLink.room_code_check(text) checks for typos first.
  • The steps with entering again are in the sample's samples/common/detphys_sample_room.gd (the same behaviour as Unity's DetPhysRoomOpener). The C# layer has DetPhysLink.CreateRelay, DetPhysLinkHub, DetPhysRoomCode and DetPhysRoomOpener (addons/detphys/csharp/DetPhysLinks.cs, used as in Unity).

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/push, detphys-sample/stack), 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) -> HostRoom or JoinRoom -> Poll every frame -> once GetRole() is 0 / 1, use it as the LocalPeer and give the link to a session (UDetPhysRtSession::CreatePush and so on).
  • Read the state with GetInfo() (FDetPhysLinkInfo) and GetLinkError(). RoomCodeCheck(Text) catches typos before any traffic.
  • UDetPhysRoomOpener::OpenRelayRoom(...) (OpenHubRoom for the test lobby UDetPhysLinkHub) holds the steps with entering again (the same as Unity's DetPhysRoomOpener).
  • The shortest way is a match component. Add UDetPhysRtMatchComponent (UDetPhysStackMatchComponent for stacking) to an Actor and call Host Relay Room / Join Relay Room. The component creates the session once the role is known, steps it in Tick and reports through Delegates such as On Connected and On 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 PushVersus and PushComponents (built only with the components) and the commandlet -run=DetPhysVersus (stacking too) take the launch options relay=, 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.Sample.Link (room codes, the test lobby, relay time-out, two components playing each other) runs from Session Frontend > Automation.

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_eos_desc_default from detphys_eos.h (a separate library, detphys_eos), put in the portal values and create the transport with detphys_eos_link_create. The rest is the same as any transport: the host calls detphys_link_host, the guest detphys_link_join, and you call detphys_link_poll every frame. When creation fails, detphys_eos_last_error explains why; call detphys_eos_shutdown once at the end of the process.
  • 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_link_info.path is the path as seen from your side; if either side reports DETPHYS_LINK_PATH_RELAYED, the EOS relay is in between. The result (the hash) is the same over the relay.
  • 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_link_info.max_packet). The largest datagram a DetPhys session sends is a resync state chunk of about 1060 bytes, so it fits.
  • Relay control (detphys_eos_desc.relay): DETPHYS_EOS_RELAY_ALLOW (default; relay only when a direct path fails), DETPHYS_EOS_RELAY_FORCE (always relay; to test the relayed case), DETPHYS_EOS_RELAY_NEVER (never relay; fails with NETWORK if 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). Set DETPHYS_EOS_FLAG_NEW_DEVICE_ID in flags for 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.loadLibrary("EOSSDK") and com.epicgames.mobile.eossdk.EOSSDK.init(activity) from your Activity (otherwise creation fails with BACKEND and the message says EOS_Android_JavaVMNotStored). Add the EOS SDK aar (eossdk-StaticSTDC-release.aar) and the AndroidX libraries it uses (androidx.browser, androidx.core, androidx.security:security-crypto) with Gradle, and the INTERNET and ACCESS_NETWORK_STATE permissions. You can pass Context.getFilesDir() or similar as cache_dir.
  • iOS: not available in this version (in Unity and Godot, DetPhysEos.IsAvailable is false on iOS).
  • Where the SDK goes (when you build the core yourself): put the SDK folder from Epic's zip at sdk/eos/SDK (so that sdk/eos/SDK/Include/eos_sdk.h exists) and unpack the Android and iOS zips over the same SDK folder (for Android, libEOSSDK.so is taken out of the aar and linked). CMake's DETPHYS_EOS is AUTO by default (built when the SDK is found, left out otherwise). Set it to ON to require it (configure stops without the SDK). For another place pass -DDETPHYS_EOS_SDK_DIR=<SDK folder>. On Windows build with MSVC or clang-cl for x64.

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)

UnityGodot
WindowsEOSSDK-Win64-Shipping.dll under Assets (for example Assets/Plugins/x86_64)EOSSDK-Win64-Shipping.dll in addons/detphys/bin/windows (next to the executable in an exported game)
Androideossdk-StaticSTDC-release.aar under Assets/Plugins/Androideossdk-StaticSTDC-release.aar in addons/detphys/eos/android. Export with the Gradle build
  • DetPhys adds the Android Gradle settings: the AndroidX libraries the aar uses (androidx.appcompat, androidx.browser, androidx.security:security-crypto) and core library desugaring, which the aar requires (coreLibraryDesugaringEnabled and com.android.tools:desugar_jdk_libs). 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 of res://android/build/build.gradle, marked with // 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.aar, included in the package and the addon). It is called automatically when the first transport is created.
  • When EOS cannot be used (the files are missing), the other transports keep working. Check with DetPhysEos.IsAvailable in Unity and Godot C#, and DetPhysLink.eos_available() in Godot GDScript.

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.Find() looks for detphys_eos.ini in Application.persistentDataPath (on Android, the app's external files folder) and in the executable's folder.
  • In the Editor (Windows), the EOSSDK-Win64-Shipping.dll under Assets is loaded before the first call.
  • The match components (Connection: Eos) read the same file: the path in Eos 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 for detphys_eos.ini in user://, the app's external files folder on Android and the executable's folder. The settings keys are product_id, sandbox_id, deployment_id, client_id, client_secret, product_name, product_version, relay ("allow" / "force" / "never"), display_name, cache_dir and log_level.
  • You can also call the GDExtension's DetPhysLink.eos(settings) directly (prepare Android with DetPhysEos.prepare_android()).

Godot (C#, addons/detphys/csharp): 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.Transport
  • DetPhysEosSettings.Find() looks for detphys_eos.ini in user://, the app's external files folder on Android and the executable's folder. CreateLink prepares 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 (/sdcard/Android/data/<package>/files/) 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_eos calls 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.dll (from SDK/Bin of your EOS SDK) in your project's Binaries/Win64 folder (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, and GetEosError() 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, ClientId and ClientSecret in [eos]) with LoadEosSettings. FindEosSettingsFile looks for detphys_eos.ini in the project's Saved folder, the project folder and the folder of the executable. ClientSecret is 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::Close frees an EOS transport at once, so you can create the next one right away (the last GetInfo and GetLinkError stay readable). UDetPhysRoomOpener also 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 screen
  • UDetPhysEos::OpenEosRoom makes a guest that comes before the host try again every second for up to 60 seconds (change it with RetryForMs and RetryEveryMs). To create the session yourself, make the link with UDetPhysEos::CreateEosLink(Outer, Settings) and call HostRoom / 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.ini in the project's Saved folder 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= and bucket=. The -run=DetPhysVersus commandlet 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.
PairPathRound trip avg (min) [ms]B/tick (push)Frame avg [ms]
Two processes on one PCdirect19–28 (10–14)32–330.3–0.9
Two processes on one PCrelay (FORCE)31–34 (26–29)330.4–0.5
PC ↔ S9 (same Wi-Fi)direct29–35 (14–16)33PC 0.3–0.4, S9 2.2–3.3
PC ↔ S9 (same Wi-Fi)relay (FORCE)40 (20–22)33–34PC 0.3, S9 3.1
PC (home line) ↔ S9 (LTE)direct / relayed on one side53–59 (45–50)33PC 0.4, S9 2.2–3.0
PC (home line) ↔ S9 (LTE)relay (FORCE)60 (49–51)34PC 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_transport 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.

DetPhys is not affiliated with Box2D or Box3D and is not endorsed or recommended by Box2D, Box3D or their author. It uses Box2D v3 and Box3D, both under the MIT license, as its physics.

LicensesMatches the current versions (2026-11)

© 2026 PetafProductsContactPrivacy

This site uses no analytics or tracking.

↑↓ to choose, Enter to open, Esc to close