DetPhysDocs日本語

Quick start

Open a sample and run it as two players on one PC, then on a PC and an Android device. Using the Unity package from the Asset Store? Go straight to Unity. Put both devices on the same Wi-Fi (LAN), or connect them with a room code through a relay on your own server (8. Transports and room codes).

EngineTwo players on one deviceA PC and an Android device
UnityStacking (turn-based) and push (real-time, with moving field) samplesPlay the same samples against each other
GodotThe same two samples as Unity (stacking and push, with moving field)Play the same samples against each other. They also connect to the Unity samples
UnrealMaps for the push sample (real time, with moving field; one uses the sessions directly, one is built with the match components), a map for the 3D push sample (with a turntable) and headless matches for stacking and pushPC against PC (LAN, or a room code on your own relay). They also connect to the Unity and Godot samples. Android with UE 5.8

The Unity and Godot sample screens are in English by default (the menu's Language / 言語 or the launch option lang=ja switches to Japanese; the OS language does not change it). Button names below are the English ones. The Unreal sample shows English (only the message for a peer with different settings switches to Japanese with the launch option lang=ja).

Code examples

The code for the engine you chose above. In every engine, inputs become integers before they go in, and both devices use the same settings, rule and shapes (in the same order).

Step a world and compare hashes

using DetPhys;

using var world = new DetPhysWorld(DetPhysWorldSettings.Default);
var chain = DetPhysHashChain.Start;
// Step 100 ticks, folding every tick's hash into a chain
for (int i = 0; i < 100; i++)
{
    world.Step();
    chain = chain.Add(world.Hash);
}
// This is the value you compare with the peer (the same on both)
Debug.Log($"tick {world.Tick} hash {DetPhysHash.ToHex(world.Hash)}");
var world := DetPhysWorld.create(DetPhysWorldSettings.new())
# Step 100 ticks, folding every tick's hash into a chain
var chain := world.step_chain(100, DetPhys.chain_begin())
# This is the value you compare with the peer (the same on both)
print(world.get_tick(), " ", world.get_hash_hex())
using DetPhys;

using var world = new DetPhysWorld(DetPhysWorldSettings.Default);
// Step 100 ticks, folding every tick's hash into a chain
ulong chain = world.StepChain(100, DetPhysHash.ChainBegin);
// This is the value you compare with the peer (the same on both)
GD.Print(DetPhysHash.Hex(world.Hash));
#include "DetPhysWorld.h"
#include "DetPhysLibrary.h"

void AMyWorldActor::BeginPlay()
{
    Super::BeginPlay();
    UDetPhysWorld* World = UDetPhysWorld::CreateDetPhysWorld(this, FDetPhysWorldSettings());
    // Step 100 ticks, folding every tick's hash into a chain
    int64 Chain = World->StepTicksWithChain(100, UDetPhysLibrary::HashChainBegin());
    // This is the value you compare with the peer (the same on both)
    UE_LOG(LogTemp, Log, TEXT("tick %lld hash %s chain %llx"), World->GetTick(), *World->GetStateHashHex(), Chain);
}
Event BeginPlay
  → Create DetPhys World (default Settings)
  → Step Ticks (Count 100)
  → Get State Hash Hex → Print String

A real-time match (built-in push)

using DetPhys;

// Both devices: the same settings, rule and shapes (in the same order)
var settings = DetPhysRtSettings.Default;   // input delay 0, prediction 10
settings.sessionId = 0x16;
var push = new DetPhysPushSettings { seed = matchSeed };
var link = isHost ? DetPhysUdpLink.Connect("192.168.1.7", 47500) : DetPhysUdpLink.Listen(47500);
// 0 = host (the reference on a desync), 1 = guest
var session = DetPhysRtSession.CreatePush(settings, push, shapes, isHost ? 0 : 1, link.Endpoint);
var driver = new DetPhysRtDriver(settings.world.tickHz);
var input = new int[DetPhysPush.InputWords];

// Every frame (Update)
session.Poll();
for (int k = driver.Due(DetPhysRtSession.NowUs); k > 0; k--)
{
    // Inputs are integers before they go in
    input[0] = DetPhysPush.QuantizeMove(Input.GetAxisRaw("Horizontal"));
    input[1] = jump ? DetPhysPush.ButtonJump : 0;
    session.Advance(input, out var frame);
}
while (session.TryGetConfirmed(out var c))
{
    // Confirmed ticks (the same hash on both peers): c.tick, c.hash
}
// Draw (the current state, predictions included)
int n = session.World.ReadBodies(views);
# The real-time push node
var rt := DetPhysRtMatch.new()
# Both devices: the same settings, rule and shapes (in the same order)
rt.shape_files = shape_files
rt.rules = DetPhysPushRules.new()
add_child(rt)
# Inputs are integers before they go in
rt.input_source = func(tick: int) -> PackedInt32Array:
	var move := DetPhysRtMatch.quantize_move(Input.get_axis("left", "right"))
	var jump := 1 if Input.is_action_pressed("jump") else 0
	return PackedInt32Array([move, jump])
# Confirmed ticks (the same hash on both peers)
rt.tick_confirmed.connect(func(tick, hash, flags): print(tick, " ", DetPhys.hash_hex(hash)))
# 0 = host (the reference on a desync), 1 = guest
rt.start(0, DetPhysLink.udp_connect("192.168.1.7", 47500))
using DetPhys;
using Godot;

// Both devices: the same settings, rule and shapes (in the same order)
var push = DetPhysPush.Desc(seed: matchSeed);
var link = isHost ? DetPhysUdpLink.Connect("192.168.1.7", 47500) : DetPhysUdpLink.Listen(47500);
// 0 = host (the reference on a desync), 1 = guest
var session = DetPhysRtSession.CreatePush(push, isHost ? 0 : 1, shapes, link.Transport, link);
var input = new int[DetPhysPush.InputWords];
ulong nextUs = DetPhysTurnSession.NowUs;

// Every frame (_Process)
ulong now = DetPhysTurnSession.NowUs;
session.PollAt(now);
// Once per tick of a 60 Hz clock (at most 3 per frame when behind)
for (int k = 0; k < 3 && now >= nextUs; k++, nextUs += 1_000_000 / 60)
{
    // Inputs are integers before they go in
    input[0] = Mathf.Clamp(Mathf.RoundToInt(Input.GetAxis("left", "right") * 100f), -100, 100);
    input[1] = Input.IsActionPressed("jump") ? 1 : 0;
    session.AdvanceAt(now, input);
}
while (session.TryGetConfirmed(out var c))
{
    // Confirmed ticks (the same hash on both peers): c.tick, c.hash
}
#include "DetPhysMatchComponents.h"
#include "DetPhysLibrary.h"
#include "DetPhysLink.h"

// Header: UPROPERTY() TObjectPtr<UDetPhysRtMatchComponent> Match;
//         UFUNCTION() void HandleTick(int64 Tick, int64 Hash, int32 Flags);
AMyMatchActor::AMyMatchActor()
{
    Match = CreateDefaultSubobject<UDetPhysRtMatchComponent>(TEXT("Match"));
}

void AMyMatchActor::BeginPlay()
{
    Super::BeginPlay();
    // Both devices: the same settings, rule and shapes (in the same order)
    Match->Settings.SessionId = 0x16;
    Match->Rules.Seed = MatchSeed;
    Match->ShapeFiles = ShapeFiles;
    // Inputs are integers before they go in
    Match->InputSource = [this](int64 InTick, TArray<int32>& Out)
    {
        Out = UDetPhysLibrary::MakePushInput(UDetPhysLibrary::QuantizeMove(MoveAxis), bJump, bDash);
    };
    Match->OnTickConfirmed.AddDynamic(this, &AMyMatchActor::HandleTick);
    // 0 = host (the reference on a desync), 1 = guest
    Match->StartWithLink(0, UDetPhysLink::UdpConnect(this, TEXT("192.168.1.7"), 47500));
}

// Confirmed ticks (the same hash on both peers)
void AMyMatchActor::HandleTick(int64 Tick, int64 Hash, int32 Flags)
{
    UE_LOG(LogTemp, Log, TEXT("tick %lld hash %llx"), Tick, Hash);
}
Add a DetPhys Rt Match component to an actor (set Settings, Rules and Shape Files the same on both peers)
Event BeginPlay
  → Udp Connect (Address 192.168.1.7, Port 47500) → Start With Link (Local Peer 0, Link)
Event Tick
  → Make Push Input (Quantize Move (horizontal axis), Jump, Dash) → Set Local Input
On Tick Confirmed (Tick, Hash, Flags) → Print String
  • The waiting side calls Listen (Godot udp_listen, Unreal Udp Listen); the other side calls Connect with its IP. When the PC is the connecting side, Windows needs no firewall rule.
  • Which side is the host (0) is a separate choice from which side waits.

Unity

You need Unity 2022.3 LTS or newer (checked with 2022.3.62f3 and 6000.3.28f1) on Windows. The package includes a macOS library, but it has not been tested in the Unity Editor or in Players on Mac yet. For Android, add Android Build Support to that version in Unity Hub; for iOS, iOS Build Support. To build an APK with 2022.3, turn on "JDK Installed with Unity" in Preferences > External Tools.

Import the package

  1. In the Package Manager (Window > Package Manager), open My Assets, select DetPhys, then Download and Import. If you have the .unitypackage file, use Assets > Import Package > Custom Package instead.
  2. DetPhys is imported into Packages/dev.petaf.detphys (in the Project window: Packages > DetPhys). Nothing is added to Assets; that is expected.
  3. Call DetPhysCore.EnsureCompatible() once at startup in your game: a missing or too old native library then gives a clear error.

Import the samples

  1. In the Package Manager, choose In Project, select DetPhys, open Samples and click Import next to DetPhys Samples.
  2. The samples go into Assets/Samples/DetPhys/1.0.0/DetPhys Samples/. They are made for the built-in render pipeline.

The sample picker (all four samples in one scene)

  1. Open Assets/Samples/DetPhys/1.0.0/DetPhys Samples/Scenes/SampleMenu.unity and press Play. Pick Stacking duel, Push, Push on moving parts, Gear arena or 3D push (the first four are the same list as the Godot picker).
  2. In every sample, the "← Samples" button at the top right, Esc and the Android back button close the session and the link and return to the picker (even in the middle of a match, without asking). The Android back button in the picker quits the app.
  3. Each sample also has its own scene in the same Scenes folder (StackVersus, PushVersus, GearArena, Push3D). Opened directly, the top-right button is that sample's "Menu" (its settings screen).
  4. Text is sized so the short side of the screen is 720 (the same look at 720x1280, 1280x720, 1920x1080 and on Android in either orientation).

Two players on one PC: stacking (turn-based)

  1. In the picker choose Stacking duel, then "Two players on this device (loopback)".
  2. Controls: mouse for the position, wheel or Q / E to rotate, click or Space to drop. Whoever drops a piece loses. The core's rule picks the next shape from a seed (the current and next shapes are shown at the top).

Two players on one PC: push (real time, zero input delay)

  1. In the picker choose Push (or Push on moving parts), then "Two players on this device". P0: A D to move, W to jump, S to dash; P1: ← → ↑ ↓. Gamepads (left stick, A jump, X / B dash) and touch also work.
  2. The "Moving" options add a spinning gear, a sliding platform and a U-shaped lift (on two devices, pick the same on both).
  3. The rule is the core's built-in push (DetPhysRtSession.CreatePush). The same rule is also written in C# in the sample (PushVersus/Runtime/CSharpPushRule.cs) as an example of writing your own rule; in a built player the launch option rule=csharp switches to it. The results are the same and the two connect to each other.

3D push (Box3D, real time, zero input delay)

  1. In the picker choose "3D push" (or open Scenes/Push3D.unity).
  2. "Two players on this device": P1 moves with WASD, jumps with Space, dashes with Shift and drops a box with E; P2 uses the arrows, Right Ctrl, Right Shift and Enter. Touch: drag on the left, buttons at the bottom right.
  3. "Spinning turntable" (on by default) adds a spinning concave table at z = +7 m (a 16-sided hull disc with three low walls, a kinematic body moved as a function of the tick). It carries whatever lands on it. On two devices, choose the same on both.
  4. Two devices: "Host on this network (P1, waits)" / "Join on this network (P2, connects)" (default port 47800), "Make a room / Enter a room (relay)" or the EOS rooms. When the PC connects, no firewall rule is needed.
  5. Top left: the lamp of the confirmed hashes, the rollback depth, the peer, and "Nudge 1 ULP" (the desync debugger's report appears at the bottom, and the state resyncs by itself).
  6. The rule is written in C# in the sample (DetPhysRtRule3D) and gives the same results as the core's built-in 3D push (detphys_rt_create_push3d). It also connects to the Godot "3D push" sample.

A PC and an Android device

  1. Add the scenes to the build: in File > Build Settings (Unity 6: File > Build Profiles), add Scenes/SampleMenu.unity from the imported samples first, then StackVersus, PushVersus, GearArena and Push3D from the same folder.
  2. Switch the platform to Android. In Player Settings, set Scripting Backend to IL2CPP, tick ARM64 in Target Architectures and set Minimum API Level to Android 8.0 (API level 26) or higher. Build the APK and install it (Build And Run installs it on a device connected over USB).
  3. Android: open the app, pick the same sample as on the PC, choose "Wait" and "Guest (P1)", then start. Note the IP address shown as "This device". In Gear arena and 3D push the side that waits is the host: on Android choose "Host (P1, waits)" (Gear arena) or "Host on this network (P1, waits)" (3D push), and on the PC "Guest (P2, connects)" or "Join on this network (P2, connects)".
  4. PC: press Play in the Editor (or run a Windows player built from the same scenes), pick the same sample, choose "Connect", enter the Android IP in "Peer IP", choose "Host (P0)", then start.
    • When the PC connects, no Windows firewall rule is needed (replies arrive as answers to what the PC sent).
    • Which side is the host (the reference on a desync) is chosen separately from which side listens.
    • Default ports: 47200 for stacking, 47500 for push, 47700 for Gear arena, 47800 for 3D push (same on both).
  5. In the push sample you can add test delay ("Test: delay ms", e.g. 30:60) and loss ("loss ‰") to the packets you send (use the same values on both). The confirmed results stay the same.
  6. Not on the same network: make a room on one device and enter its 6-digit room code on the other, through EOS P2P (EOS P2P; the EOS SDK comes from Epic) or your own relay (8. Transports and room codes; its source is in the package's Tools~/detphys_relay).

Add a match to your own scene

  1. Add DetPhys Rt Match 3D to a GameObject (2D: DetPhys Rt Match; turn based: DetPhys Turn Match / DetPhys Turn Match 3D).
  2. In the Inspector pick the Rule (Built In = the core's built-in rule, C Sharp = your rule [Rule or RuleFactory from code]), the Push settings of the rule and the Connection (Local = two players on this device, Udp, Relay [room codes] or Eos). The rule settings, the shapes and the Session Id must be the same for both players.
  3. Give the input every frame with InputSource ((peer, tick) → integers) or LocalInput. On Play it starts in Start, steps by the tick clock in Update, rolls back, and copies the bodies to Transforms as the Views settings say (Create Views also makes simple views).
  4. Events come as UnityEvents: onConnected, onRoomCode (the code the host gives to the other player), onTickConfirmed (the same hash for both players), onDesync / onDesyncReport (the desync debugger's report), onPeerLost, onError, onMatchEnded. Turn based: Submit on onLocalTurn, results in onTurnFinished and onMatchOver.
  5. Your own concave shapes: open Window > DetPhys > Shape Baker (or right-click an image > DetPhys > Open in Shape Baker), pick a texture or sprite with transparency, check the preview, then Save. Select the GameObject with the match component and click Add to the Shapes of … in the window: the shapes are used as mesh 0, 1, … in that order (the same list on both players). See 3. Concepts for how the shapes are baked.
  6. With the launch option driver=component, the "push" and "3D push" samples play the same match built from the components only (e.g. -detphys "game=push3d,driver=component,local=1"; the other player may run the same sample without the component).
The 2D push match built with the DetPhys Rt Match component: orange boxes, purple baked concave shapes and two yellow circles on the floor of the arena
The 3D push match built with the DetPhys Rt Match 3D component: boxes, spheres and hulls next to the turning teal platform

How Create Views looks: with Material empty, the views use the package's default material (shader DetPhys/Default View). It is shaded without any light in the scene and draws in the built-in render pipeline, URP and HDRP, also in Android and other player builds. With Color By Shape on, the color follows the body type and shape (static = gray, kinematic = teal, boxes = orange, spheres / circles = yellow, capsules = green, hulls / baked shapes = purple). For your own look, set Material in Views; all the views use that one material. For URP make a material with Universal Render Pipeline/Lit, for HDRP one with HDRP/Lit, and so on. Reference the material from a scene or keep it in Resources so that builds include it. To give each body its own model, put Transforms in Bodies (by body id).

using DetPhys;

// a GameObject with the DetPhys Rt Match 3D component (Rule: Built In, Connection: Udp / Relay / Eos / Local)
var match = GetComponent<DetPhysRtMatch3D>();
// integers only: quantize the stick and the buttons before they go in
match.InputSource = (peer, tick) => DetPhysPush3D.Input(
    DetPhysRtMatch3D.QuantizeAxis(Input.GetAxisRaw("Horizontal")),
    DetPhysRtMatch3D.QuantizeAxis(Input.GetAxisRaw("Vertical")),
    jump ? DetPhysPush3D.ButtonJump : 0);
match.onRoomCode.AddListener(code => Debug.Log("Room code: " + code));
match.onTickConfirmed.AddListener((tick, hash, flags) =>
{
    // the same hash on both players
});
match.onDesyncReport.AddListener(report => Debug.LogWarning(report));
  • Short examples (worlds, sessions, your own rules, EOS) are in the package's README.md (Packages/dev.petaf.detphys/README.md). The samples' scripts are under Assets/Samples/DetPhys/1.0.0/DetPhys Samples/.

Export to iOS

  • You need Unity's iOS Build Support. Set Target minimum iOS Version in Player Settings to 15.0 or newer. iOS uses IL2CPP and devices (arm64) only (you cannot build for the Simulator).
  • The package includes the iOS library (Runtime/Plugins/iOS/libdetphys.a). Unity links it into UnityFramework in the exported Xcode project, so no extra settings or post-processing are needed.
  • You can export the Xcode project on Windows. Building and signing it in Xcode needs a Mac (or a CI service that runs on a cloud Mac).
  • The license notices go to Data/Raw/DetPhys/THIRD_PARTY_NOTICES.md in the Xcode project (in the app, DetPhys/THIRD_PARTY_NOTICES.md under Application.streamingAssetsPath).
  • If the target iOS version is older than 15.0, or the build is for the Simulator, a [DetPhys] warning appears in the Console when the build starts.
  • EOS P2P is not available on iOS in this version (DetPhysEos.IsAvailable is false). LAN UDP and your own relay work. For UDP on a LAN, iOS asks for local network permission (NSLocalNetworkUsageDescription in Info.plist).

Godot

You need Godot 4.3–4.8 (for C#, a .NET build of 4.4 or newer; checked with 4.7.2 .NET).

Two players on one device

  1. Open engines/godot/DetPhysSample in Godot (if Godot crashes on the first import, open it again).
  2. Open a sample scene and run it with "Run Current Scene" (F6):
    • Stacking (turn-based): res://samples/stack_versus/stack_versus.tscn
    • Push (real time, zero input delay): res://samples/push_versus/push_versus.tscn (the menu also has the moving field)
    • 3D push (Box3D, real time, zero input delay, GDScript only): res://samples/push3d/push3d_versus.tscn (the menu also has the spinning turntable, on by default)
    • All of them can be picked from the main scene (the sample picker)
  3. Choose "Two players on this device". The controls are the same as in the Unity samples (stacking: mouse for the position, wheel or Q / E to rotate, click or Space to drop; push: A D to move, W / Space to jump, S / Shift to dash, P1 uses the arrow keys; touch: drag on the left half, top right to jump, bottom right to dash). 3D push: WASD / left stick to move, Space to jump, Shift to dash, E to drop a box, P2 uses the arrows, Enter, . and /; touch: drag on the left half, buttons at the bottom right. "Nudge 1 ULP" at the top right moves the guest's state by one floating-point step: the desync debugger's report (tick, body, field, ULP, cause) appears at the bottom and the session resyncs by itself.

A PC and an Android device (Godot with Godot, or Godot with Unity)

  1. Export an APK with the Android preset in export_presets.cfg and install it (arm64, Android 8.0 or newer; C# Android export needs 4.7 or newer).
  2. Choose "Wait (guest)" on Android and "Connect (host)" with the Android IP on the PC, then start (when the PC connects, no firewall rule is needed).
  3. The ports and settings are the same as the Unity samples (47200 for stacking, 47500 for push), so the other side can be a Unity sample (for the push moving field, pick the same on both).
  4. 3D push (port 47800) follows Unity's "3D push": "Host on this network" (P1, waits) on one side, the peer IP and "Join on this network" (P2, connects) on the other. Pick the same turntable setting on both. The other side can be the Unity sample.
  5. The 3D push can also run with the same rule written in C# (DetPhysSamplePush3DRule in samples/rules3d/DetPhysSampleRules3D.cs and the 3D match node DetPhysRtMatch3D). Add rule=cs to the launch options (without the turntable only, .NET build of Godot) for an automatic match without drawing, e.g. godot --headless --path DetPhysSample -- "detphys=game=push3d;rule=cs;peer=0;connect=127.0.0.1:47800;auto=1;quit=1". The other peer can keep the built-in rule (the Godot, Unity or Unreal 3D push, or a session created with detphys_rt_create_push3d in the C ABI); the confirmed tick hashes are the same.
  6. Stacking and push can also run with the same rules written in GDScript or C# (samples/rules2d). Add rule=gd or rule=cs (.NET build of Godot) to the launch options, and the sample puts that rule in the match node (DetPhysStackMatch, DetPhysRtMatch). The menu buttons (two players on this device, connect, relay and EOS rooms) start with the same rule, and it connects to peers with the built-in rule (the Unity samples too) with the same hashes.

The check scene (hashes match)

Run the main scene res://check/check.tscn (F5). The output lists [DetPhysGodot] <name> <value> OK lines and ends with [DetPhysGodot] RESULT pass=<n> fail=0 when the core on this device gives the reference hashes (with a .NET build of Godot also the C# layer; on the standard build the C# lines say SKIP). On Android the results are the [DetPhysGodot] lines in logcat.

Add it to your project

Copy addons/detphys (no editor plugin needs to be enabled). The add-on's README.md explains how to use it. Every export includes the license notices: inside the exported data at res://addons/detphys/THIRD_PARTY_NOTICES.md (in the APK, assets/addons/detphys/THIRD_PARTY_NOTICES.md), and on Windows and Linux also as DetPhys/THIRD_PARTY_NOTICES.md next to the executable.

var rt := DetPhysRtMatch.new()              # node for push (real time)
rt.shape_files = ...                       # the same shapes in the same order on both peers
rt.rules = DetPhysPushRules.new()           # built-in push settings (integers only); moving field: rules.field = DetPhysPushRules.FIELD_ALL
add_child(rt)
rt.input_source = func(tick: int) -> PackedInt32Array:
	return PackedInt32Array([DetPhysRtMatch.quantize_move(Input.get_axis("left", "right")), 1 if Input.is_action_pressed("jump") else 0])
rt.start(1, DetPhysLink.udp_listen(47500))  # 0 = host, 1 = guest

Export to iOS

  • The add-on includes the iOS GDExtension (addons/detphys/bin/ios/libdetphys_godot.xcframework, a static library). The ios.arm64 line in detphys.gdextension puts it into the export, so adding an iOS export preset is all you need.
  • iOS 15.0 or newer (set Min iOS Version in the export preset to 15.0 or newer), devices (arm64) only.
  • Godot on Windows and Linux can export the Xcode project. Building and signing it in Xcode needs a Mac (or a CI service that runs on a cloud Mac).
  • Exporting a project that uses C# to iOS is still experimental in Godot and needs Godot on macOS. DetPhys's C# layer has not been tested on iOS in this version; on iOS, use DetPhys from GDScript.
  • The license notices go into the exported data (.pck) at res://addons/detphys/THIRD_PARTY_NOTICES.md.
  • EOS P2P is not available on iOS in this version. LAN UDP and your own relay work. For UDP on a LAN, iOS asks for local network permission (NSLocalNetworkUsageDescription).

Demo: Gear Arena (Unity and Godot, cross-engine)

Two rods push 120 concave pieces inside a spinning concave gear. It exists in both Unity and Godot, and the two play each other (Unity on a PC with Godot on Android, too). At the edge of the screen: an injected-delay slider (0..150 ms), the input delay, the hash lamp, the rollback meter, the opponent's engine, "Nudge 1 ULP" and "Show convex pieces".

  • Unity: pick Gear arena in the sample picker, or open Scenes/GearArena.unity of the imported samples. Godot: "Gear arena" in the menu (C#, so the .NET build). Port 47700.
  • Details, the screen items and measured numbers: Gear Arena.

Unreal Engine

You need Unreal Engine 5.4–5.8 (automation tests checked with 5.8.4; the plugin builds on all of 5.4.4–5.8.4), Win64.

World and hash (one device)

  1. Open engines/unreal/DetPhysSample/DetPhysSample.uproject (it loads the plugin from engines/unreal/DetPhys).
  2. Run the eight DetPhys.Sample tests (Abi, Empty100, Scene600, Tower720, Net, Net3D, Rule3D, Link) in Tools > Session Frontend > Automation: all match the reference hashes (Net runs stacking and push with two peers in one process; Net3D runs the 3D push [with and without the turntable, with delay and loss, with a nudge] and checks the coordinate conversion and the hull faces; Rule3D runs 3D rules written in C++ [push, turn-based stacking, a spinning table] and the 3D match components; Link checks room codes, rooms in the test lobby and the match components).
  3. Blueprint: Create DetPhys World (integer settings: tick rate, substeps, gravity in mm/s², worker threads) → Step every simulation tick → compare Get State Hash between peers.
  4. In your own project, put engines/unreal/DetPhys in <YourProject>/Plugins/DetPhys and enable the plugin. From C++, add "DetPhysRuntime" to your module's dependencies (and "DetPhysCore" to call the core C ABI directly); UDetPhysWorld::GetNative() returns the detphys_world*. All functions in 7. API reference (turn-based, real-time, built-in push, moving concave shapes, desync debugger, 3D) can be called from C++. The match API (UDetPhysLink, UDetPhysTurnSession::CreateStack, UDetPhysRtSession::CreatePush and the like) can also be called from Blueprint (7. API reference).

The sample picker

  1. Open the map Content/Maps/SampleMenu and press Play (it is also the first map of a packaged game). Pick Push (PushVersus, a sample written in C++), Push on moving parts, Push, built with components (PushComponents) or 3D push (Push3D), and how to play: "Two players on this PC", "Wait (guest, port 47500)", "Connect (host)", "Make a room (relay)" or "Enter the room (relay)". Type the peer IP, the relay and the room code in the "Two devices" box on the right. English is the default; switch with "日本語" at the top (kept for the next start).
  2. In every sample, "← Samples" at the top right, Esc or the Android back button closes the session and the transport and goes back to the picker (right away, even mid-match; you can listen on the same port again afterwards). Esc in the picker quits the game.
  3. The launch option -detphys="game=push|field|components|push3d;..." skips the picker and starts that sample (it reads the rest of the options as before). Opening a sample map directly still works.
  4. Text size follows the short side of the screen as 720 (Config/DefaultEngine.ini, UserInterfaceSettings: ShortestSide, 1.0 at 720), so 1280x720, 1920x1080 and tall windows look the same.

Two players on one PC (push, real time, zero input delay)

  1. Pick "Push > Two players on this PC" in the picker, or open the sample map Content/Maps/PushVersus and press Play (no art: the bodies are extruded convex polygons).
  2. By default two players share this PC. P0: A D to move, W or Space to jump, S or Shift to dash (gamepads too); P1: arrow keys.
  3. The launch option -detphys="field=all" adds the moving field (spinning gear, sliding platform, rising U) (or pick some with gear, platform and lift joined by +).

Two PCs (LAN), also against the Unity and Godot samples

  1. Start the waiting side (guest) with -detphys="peer=1;listen=47500" and the connecting side (host) with -detphys="peer=0;connect=<peer IP>:47500". The port and settings are the same as the Unity and Godot push samples, so the other side can be a Unity or Godot sample (pick the same moving field on both).
  2. Stacking (turn-based) has no drawn sample yet (planned), only headless matches (a commandlet): UnrealEditor-Cmd DetPhysSample.uproject -run=DetPhysVersus -detphys="game=stack;peer=0;connect=127.0.0.1:47200;auto=1" (game=push for push; the launch keys and log lines are the same as in the Unity and Godot samples).

3D push (also against the Unity and Godot samples)

  1. Pick "3D push > Two players on this PC" in the picker, or open the map Content/Maps/Push3D and press Play. Two players push boxes, balls and rocks (convex hulls); a spinning concave turntable at the back carries whatever lands on it (no art: boxes, balls and the hull meshes read from the core).
  2. P1: WASD to move, Space to jump, Shift to dash, E to drop a box (gamepad: left stick, A, X, B); P2: arrows, Enter, ., /. N nudges the state by 1 ULP on purpose, and the desync debugger's report and the resync show on screen.
  3. For two devices, start the waiting side with "Wait (host, port 47800)" or -detphys="game=push3d;peer=0;listen=47800" and the connecting side with "Connect (guest)" or -detphys="game=push3d;peer=1;connect=<peer IP>:47800" (in 3D push, as in the Unity and Godot 3D push, the waiting side is the host). The rule is the built-in 3D push (UDetPhysRtSession::CreatePush3D) with the same settings, so the other side can be the Unity or Godot "3D push" and the confirmed tick hashes are the same. Use the same turntable setting on both (field=table or field=none; the picker starts with the turntable). Relay rooms use the same keys as in 2D (relay=, room=; the default bucket is detphys-sample/push3d).
  4. Headless match: UnrealEditor-Cmd DetPhysSample.uproject -run=DetPhysVersus -detphys="game=push3d;peer=0;connect=127.0.0.1:47800;auto=1;field=table" (the launch keys and log lines are the same as in the Unity and Godot 3D push). Add rule=cpp (without the turntable only) to run the same rule written in C++ (UDetPhysSamplePush3DRule in DetPhysSampleRules3D.h, UDetPhysRtSession::Create3D); the other peer can keep the built-in rule.
  5. Coordinates: the core has y up and metres (right-handed), Unreal has z up and centimetres (left-handed). The plugin's readback (ReadTransforms3D, ReadBodies3D, GetHull3DMesh and the like) returns Unreal coordinates, ready for Actors and components. The rule settings and the input ([move x, move z, buttons]) stay in core coordinates (Unreal X = core x, Unreal Y = core z; Make Push 3D Input builds the input from an Unreal X / Y direction).

Over the internet (your own relay and a room code)

  1. Run your own relay (detphys_relay; see 8. Transports and room codes) somewhere.
  2. Start the side that makes the room with -detphys="relay=<relay host or IP>[:<port>];peer=0": the 6-digit room code appears in the log and on screen. The side that enters uses -detphys="relay=<the same relay>;room=<room code>". This works for the push map and for the commandlet (game=stack too), and the other side can be a Unity or Godot sample (the default buckets detphys-sample/push and detphys-sample/stack are the same).

Building with the match components (Blueprint only is fine)

  1. The sample map Content/Maps/PushComponents is the same push game built only with UDetPhysRtMatchComponent and its Delegates (ADetPhysRtMatchSampleActor; by default two players on this PC through a room in the test lobby). Its launch options are the same as PushVersus (relay=, room=, connect=, listen=).
  2. Add a DetPhys Rt Match component (DetPhys Stack Match for stacking) to your Actor (a Blueprint is fine) and make Shapes (read with Load Shape Files), Settings and Rules the same on both peers.
  3. Call Host Relay Room (make a room) or Join Relay Room (enter by code), or Start With Link on a LAN (a Udp Listen / Udp Connect link). On Room Ready comes when the role is decided, On Connected when connected.
  4. Every frame put your input (integers, e.g. from Make Push Input) into Local Input. Confirmed ticks arrive in On Tick Confirmed (the same hash on both peers); for stacking, Submit on On Local Turn and read results in On Turn Finished. Draw from Get Session's body readback.

Android

  • Android (arm64-v8a, Android 8.0 or newer) works with UE 5.8: the plugin includes the Android library, so package the game for Android as usual. Checked with UE 5.8.4 on a Galaxy S9 (the same hashes as on a PC, 60 fps in the push samples).
  • EOS P2P is Windows only in Unreal in this version; on Android use LAN UDP or your own relay.

When something goes wrong

SymptomCheck
Does not connect (stays CONNECTING)Same LAN (over the internet, use a room code on your own relay)? Same port? Is Windows the connecting side? Are both configurations equal (session id, rule settings, push moving field, shapes and their order)? Peers with different configurations drop each other's messages. Cores with rt version 7 / turn version 9 then report which part differs (version, config, rule, shapes, kinematic) (DETPHYS_RT_FRAME_TAG_MISMATCH, detphys_tag_info; see 5. Troubleshooting desyncs). The samples (Unity, Godot, Unreal) show "Peer has different settings (differs: rule). Stopped connecting: …" once they know what differs, and stop connecting
Does not connect to an older APKPeers with different protocol versions do not connect. Rebuild both from the same version
The other peer crashedThe session keeps waiting (after 5 s without packets it reports PEER_LOST). Restart the app on the crashed side and create the session with the same settings: it rejoins where it left off
DesyncDesyncs are found by the hash check and repaired automatically from the host's state. To find the cause, see 5. Troubleshooting desyncs

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