UGS Multiplayer Widgets - Transition to Game Scene on Session Join

Hello,
I’m completely new to game development, but decently experienced in coding (python, web, pcb firmware).

I’m trying to create a simple 1v1 multiplayer game. So far I’ve accomplished the following:

  • Created a Menu Scene, Lobby Scene, and Game Scene
  • Created a basic working prototype of the playable game in the Game Scene
  • Implemented the UGS Multiplayer widgets to create a session, view sessions (lobby), and join a session, by using the new widgets (Right-click hierarchy → Multiplayer Widgets)
  • Get 2 players in separate instances (Using Multiplayer Play Mode) to spawn into the same session, with player movement synced

I’ve been struggling for days trying to figure out how to then load the “Game” scene, so the 2 players aren’t just floating around in the skybox. Currently, the player prefabs are instantiated when each player joins the session, and each player’s controls work. But they appear in the Lobby scene.

I’ve gone down several rabbit holes trying to figure out how to load the Game Scene for both players upon joining the session. I’ve dug into:

  • Unity Events and triggering an OnClick event
  • CustomWidgetsNetworkHandler.cs
  • Loading the scene manually with a LobbyManager.cs script attached to the Lobby’s UI Canvas

None of this worked or feels right. And it feels like there’s a simple, right way to easily transition players into the Game Scene once they join the session, but for days I haven’t been able to discover it.

Is there an editable script somewhere that’s spawning the player prefabs on session join?

Any help would be greatly appreciated,
Thank you

Hi!

I’m assuming you are using Netcode for GameObjects?
It depends a bit if you’re calling the connection logic yourself or if you’re letting the Widgets do that (for example when your Connection Type is set to Relay in the Widget Configuration it will automatically connect using the Network Manager in your Scene).

The Widgets expose some Events that you could use.
Any Widget that will join a Session (for example the “Create Session” Widget or the “Session List” Widget) has a Component on its root GameObject that lets you assign Callbacks to three types of Events: JoiningSession, JoinedSession and FailedToJoinSession.

Here is a screenshot:

There you can add for example a custom LoadScene() method from a Monobehaviour you write yourself that just loads your game scene.
If you are manually calling the NetworkManager to connect your players then use the JoinedSession event to invoke your scene loading logic.
However, if it auto-connects I would advise you to use the JoiningSession event. This is because the connection might happen before your Game Scene is loaded so your PlayerPrefab would end up in the Lobby Scene just before loading the Game Scene. If the join process should fail you can handle that in the FailedToJoinSession event and transition back to your Lobby Scene.

I hope this helps!

1 Like

Thank you! This makes a lot of sense. I’ll try it!

Yes, I’m using Netcode for GameObjects.

2 Likes