Devlog 8
To the Arena
With all the significant systems online now—car control, turret aiming, firing, camera logic, and spawning—I moved on to the passage from the Lobby to the Arena, an extremely important point within the multiplayer play. This transition had to be seamless, synced across the board for everybody, and preserve everybody's role and spawn integrity during scene switch. In our game, after character selection, players will first spawn in the lobby scene. Once all the players are ready, a 30-second countdown is started. When the countdown reaches zero, all the players will get teleported to the main Arena.
Instead of writing new logic for the arena, I just reused the same CarSpawnerManager already stably used in the lobby. The idea was this: after we've completed loading the Arena scene, players would be spawned into their respective roles again, using new, networked car instances dynamically placed through our ground based spawn sampling algorithm.
I encountered a multiplayer problem while testing. When loading the Arena scene:
- The cars spawned in the lobby remained and transferred to the new scene.
- At the same time, CarSpawnerManager in the Arena spawned two additional cars.
- This left 4 cars in the Arena, disrupting the gameplay experience.
This was because Unity Netcode was storing NetworkObjects across scenes, and I hadn't cleaned up scene unload correctly on the lobby side.
The Solution: Clean Despawn Before Teleporting
To solve this issue, I created a dedicated LobbyCountdownManager. This script takes care of:
- Starting the countdown when all players are ready.
- Keeping the countdown in a NetworkVariable so all clients are in sync.
- Despawning the lobby vehicle instances right before loading the next scene.
- Triggering the loading of the Arena scene.
- Enabling CarSpawnerManager in the Arena to spawn new vehicle objects with correct authority and role assignments.
This assured a clean handoff between scenes. No duplication.