Posted May 07, 2025 by Riteshhhh
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:
This was because Unity Netcode was storing NetworkObjects across scenes, and I hadn't cleaned up scene unload correctly on the lobby side.
To solve this issue, I created a dedicated LobbyCountdownManager. This script takes care of:
This assured a clean handoff between scenes. No duplication.