ChainSafe / ChainSafe/open-creator-rails.unity

Multiplayer Sample Demo using Unity NetCode

Open
#44 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

**What**

Add a multiplayer sample demo to the UPM package alongside the existing single-player `Demo.unity` scene. The multiplayer sample uses **Unity NetCode for GameObjects** and allows multiple players to connect to the same session, each with their own wallet identity and independent subscription state.

The existing sample scripts (`MovementController.cs`, `CameraController.cs`, `Player.cs`, `GatedAssetTrigger.cs`, `GatedAssetSubscriptionHandler.cs`) are single-player only — they have no network ownership awareness and assume a single local player. The multiplayer sample extends the demo to a networked context while keeping the same OCR subscription gating mechanic.

**Why**

The current sample demonstrates the SDK for a single user in isolation. A multiplayer demo shows how the SDK behaves in a real game context — where different players in the same session may or may not hold active subscriptions to gated content. It also validates that `OpenCreatorRailsService` (a `DontDestroyOnLoad` singleton) and per-player `subscriberId`s work correctly when multiple wallets are connected simultaneously on different clients.

**How**

1. Add `com.unity.netcode.gameobjects` to the `SampleProject` package dependencies
2. Create a new `MultiplayerDemo.unity` scene (alongside the existing `Demo.unity` and `Loading.unity`) with a `NetworkManager` configured with Unity Transport (`com.unity.transport`)
3. Adapt `Player.cs` and `MovementController.cs` to extend `NetworkBehaviour` — movement and camera control run only on the local owner (`IsOwner` check); remote player representations are visible but not controllable
4. Each connected client retains its own `subscriberId` and wallet — subscription checks are per-player and per-client, not replicated or shared across the session
5. `GatedAssetTrigger` and `GatedAssetSubscriptionHandler` remain local-client-only — only the local player's subscription is checked when they interact with a gated area; the result is not broadcast to other clients
6. Add a simple host/join UI (extend `Landing.uxml` or add a new `Lobby.uxml`) that lets the player choose to host or join via IP before loading the multiplayer scene
7. Update `scripts/duplicateSamples.sh` and `Samples~/Open Creator Rails` to include the new multiplayer scene and its associated scripts

**Acceptance Criteria**

- [ ] A host and at least one joining client can connect and see each other's player in the scene
- [ ] Gated areas correctly gate per-player — a subscriber can enter, a non-subscriber is prompted to subscribe
- [ ] Subscribing on one client does not grant access to another client's gated check
- [ ] The sample works against the local Anvil + Ponder stack (see issue #42 for local setup)
- [ ] Existing single-player `Demo.unity` scene is unaffected

**Estimation**

**Dependencies**

None.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.