This is a Unity-based multiplayer Pong demo that demonstrates:
- Integration with Namazu Elements for user management and matchmaking.
- Use of Unity Netcode for GameObjects (NGO) with WebRTC for networked gameplay.
- CPU player simulation using ParrelSync for cloned projects.
- Scene management and pre-placed vs spawned network objects.
The project is designed to let the host player login manually, while a cloned instance automatically logs in as a CPU player.
This project is based (with permission) on the unity-pong-tutorial project found here.
- Manual Player Login (create account or log back in)
- CPU Player Auto Login (detected in cloned projects via ParrelSync)
- Matchmaking using Namazu Elements + Crossfire plugin
- WebRTC Peer-to-Peer Connection via Unity Netcode
- Networked Pong Gameplay (paddles, ball, scoring)
- Scene flow:
Login→PongMulti→ gameplay
- Unity 2021.3+ (or compatible LTS version)
- Namazu Elements + Crossfire services running
- A created application in Elements, in this case named
Pong - A matchmaking configuration in Elements (FIFO recommended), named
default - ParrelSync (for CPU player detection in cloned projects)
-
Clone the Project with ParrelSync
- ParrelSync allows creating a "clone" Unity instance.
- The cloned project will automatically detect itself and login as the CPU player.
-
Configure Elements Client
- Ensure
ElementsProperties.ELEMENTS_ROOT_URLpoints to your running Namazu Elements instance. - Ensure the application name (
Pong) matches your Elements setup.
- Ensure
-
Network Prefabs & Scenes
- Pre-place NetworkObjects (ball, host paddle, client paddle) in the
PongMultiscene. - Do NOT call
Spawn()manually on pre-placed scene objects — NGO will spawn them automatically. - Add any dynamically spawned prefabs (e.g., projectiles, power-ups) to NetworkManager → NetworkPrefabs.
- Pre-place NetworkObjects (ball, host paddle, client paddle) in the
-
Startup Flow
- The project starts in the
Loginscene. - Host player logs in manually (create account or sign in).
- CPU player clone logs in automatically using
CPUPlayerLoader. - After login, players can find or join a match using the default matchmaking configuration.
- Once connected, a WebRTC P2P connection is established via NGO + Crossfire plugin.
- The
PongMultiscene is loaded automatically, and gameplay begins.
- The project starts in the
-
Scene Objects vs Prefabs
- Scene objects (pre-placed in the scene) are automatically spawned by NGO. Do not call
Spawn()on them. - Only dynamically instantiated objects should be spawned manually.
- Scene objects (pre-placed in the scene) are automatically spawned by NGO. Do not call
-
NetworkVariables
- Do not write to
NetworkVariablesbefore theNetworkObjecthas spawned. - Initialize variables and subscribe to
OnValueChangedinOnNetworkSpawn().
- Do not write to
-
Ownership
- For pre-placed paddles or ball objects, use
ChangeOwnership(clientId)to assign control. - Do not try to
InstantiateAndSpawnscene objects — this causes hash mismatches and spawn failures.
- For pre-placed paddles or ball objects, use
-
WebRTC / DataChannel Timing
- Ensure
NetworkManager.Singleton.StartHost()orStartClient()completes before sending any network messages. - For proper synchronization, all initial game setup should happen in
OnNetworkSpawn()on both host and clients.
- Ensure
-
Score & UI Updates
- Use
NetworkVariablehooks to update UI across clients. - Do not attempt to directly set UI text from server logic — always update through
OnValueChangedcallbacks.
- Use
| Scene Name | Description |
|---|---|
Login |
Player login / account creation / CPU player detection |
PongMulti |
Multiplayer Pong gameplay |
- LoginViewController – Handles manual login, account creation, and profile management.
- CPUPlayerLoader – Automatically logs in CPU player in cloned projects.
- GameManager – Manages gameplay: networked paddles, ball, score, round logic.
- ElementsAuthService – Utility class to handle shared authentication logic (login, signup, profile fetching).
- Open the main project → Start Unity.
- Open the
Loginscene. - For CPU vs host testing:
- Use ParrelSync → Create Clone.
- Start clone → CPU automatically logs in.
- Log in manually in the main project.
- Matchmaking starts automatically.
- Once connection established →
PongMultiscene loads → game starts.
flowchart TD
A[Main Project Host Player] --> B[Fetch Profile]
C[Cloned Project CPU Player] --> D[Ensure Profile Exists]
B --> E[Matchmaking]
D --> E
E --> F[WebRTC Connection]
F --> G[PongMulti Scene]
G --> H[NetworkObjects Spawned]
G --> I[Ownership Assigned]
G --> J[Gameplay Begins]
G --> K[NGO Gotchas]