Networking with Scene Switching in Unity

Hello,

I use Unity and my project includes a Main Menu scene with a Main scene, using SceneSwitcher component. Could you clarify which Needle Engine components should be in each of these scenes to have networking functionality setup properly, syncing scene elements?

Please consider that the Main Menu scene uses an input field and a Join button to enter a custom room and this connection should persist after switching to the Main Scene, thus allowing users that join in using the same room name, to have the same collaborative shared environment.

Please include details, i.e. the Synced Room’s parameters, like Room Prefix “1”, URL Parameter Name room “room“, Require Room Parameter “disabled”, Create Join Button “disable” (the latter should be served through GUI).

My Main Menu has now 10 game objects, i.e.

  • Needle Engine
    Needle Engine (Project & Export), Component Generator, Skybox Export Settings, Needle Editor Sync, Compression and LOD Settings components,
  • Networking
    SyncedRoom component,
  • XR
    WebXR component,
  • Camera
    Camera and Audio Listener components,
  • Camera Target
    No components attached,
  • SpectatorCamera
    Spectator Camera, Camera and Universal Additional Camera Data components
  • SyncCamera
    SyncedCamera component
  • XRRig
    XRRig component,
  • SceneSwitcher
    SceneSwitcher component with MainScene added in Scenes list,
  • EventSystem

The Main Scene includes only the scene content with proper use of SyncedTransform, DragControls and Deletable components on the required game objects. Note that if “Needle Engine” game object is not used, these components do not have the “Needle Component” indication next to the script name but only “Script” and no TS icon indication but C# icon instead.

By uploading the project to the Needle Cloud, will the connection work flow be the same or that is handled differently like adding room parameter to the URL that should be considered during my tests locally? I do not use the “Networking” component.

Thank you!

Needle Engine includes a full networking solution for multiplayer experiences, with features like shared world state, voice chat, and session persistence (1). You can quickly get started by adding a SyncedRoom component to your scene and SyncedTransform to objects you want to synchronize (1, 2).

Needle Engine’s built-in networking is designed for real-time multiplayer and collaborative applications (3, 4, 5, 6, 7). By default, the SyncedRoom component uses networking infrastructure provided by Needle (2).

Sources: Needle Engine Docs (73%), Needle Engine Docs (73%)

1 replies left - Become PRO for more replies.
Reply to this post directly if you need further help (bottom right button)

Hello Petros,

Scene structure & component placement

The key thing to understand is that SceneSwitcher doesn’t perform a Unity-style scene load — it loads additional .glb files as children of the SceneSwitcher object. Your root scene (Main Menu) stays fully alive, which means all your networking components there persist. So your current layout is actually on the right track:

Your Main Menu scene (the root/exported scene) should keep: the Needle Engine object (with export settings), SyncedRoom, SceneSwitcher, Camera, XRRig, SyncedCamera, WebXR — basically everything you listed. This is your “host” scene that manages the session.

Your Main Scene (loaded by SceneSwitcher) should contain only the scene content — objects with SyncedTransform, DragControls, Deletable, etc. It does not need its own SyncedRoom, cameras, or Needle Engine export object, since it’s loaded into the already-running context (it can however contain for example a different “MainCamera” if you want to change the camera if another room is loaded). That also explains the “Script” vs “Needle Component” indicator: the Needle Engine object is what provides the export/compilation context, and since the Main Scene is exported as a referenced glb from the root scene, it doesn’t need its own.

Custom room join UI

Since you’re disabling the built-in Create Join Button on SyncedRoom and providing your own input field + button, you’ll need a small custom TypeScript component that calls the networking API to join a specific room. The idea is:

  • On your Join button click, read the room name from your input field
  • Set the room URL parameter or call into this.context.connection.joinRoom(roomName) (or modify the URL parameter that SyncedRoom reads from)
  • SyncedRoom with urlParameterName: "room" will look for ?room=YourRoomName in the URL, so one approach is to update the URL parameter before SyncedRoom connects, or to connect programmatically

You’ll want to set requireRoomParameter: false (disabled) so the app doesn’t block on load, and handle the join logic yourself through your GUI.

Needle Cloud deployment

The networking workflow is the same whether running locally or on Needle Cloud. SyncedRoom connects to Needle’s networking infrastructure by default regardless of where the page is hosted. The room parameter (?room=xyz) in the URL works the same way. The only thing to be aware of is that if you’re using the separate Networking component to point to a custom server URL, the localhost URL obviously won’t work in production — but since you mentioned you’re not using the Networking component, the default Needle servers will handle it and it should work identically on Cloud.

SyncedRoom parameters for your use case

Based on what you described, your SyncedRoom settings should be:

  • Room Prefix: "1" (or any string — this namespaces your rooms)
  • URL Parameter Name: "room"
  • Require Room Parameter: disabled (so the page loads without requiring ?room= in the URL immediately)
  • Join Random Room: disabled (you want users to pick a specific room name)
  • Auto Rejoin: enabled (so after SceneSwitcher loads the Main Scene, the connection is maintained)

Hope that helps — let me know if something’s unclear!

Thank you for the detailed information.

I followed your instructions and tried testing with no room selection functionality in the Main Menu, just including the default game objects mentioned in my previous message and adding debug UI information in Main Scene to better understand the issue. The following screenshot of the Main Scene is taken on my Windows computer running Unity with Chrome browser:

Please note that no “Room” parameter is included in the URL and that Editor Sync is installed. After removing that, the “editorid” parameter in the URL was absent, but still the issue persists.

Scanning the QR code on my mobile, I connected normally and chose the “Next” scene from the Needle bar below. The debug information show the same information as above but with a different ID!

So there are 2 issues, the room parameter is not included in the URL and the room ID is different.

Also it is important to mention that the user camera object is properly synced, I see the other user in the scene, but the game objects do not sync.

Some more notes…

I run the project locally and with the default single sandbox scene there is no sync issue.

In Main Scene in addition to the content, I have a game object with Scene Loading Events component and its “Opened” and “Closing” settings are empty.

I read the thread Unity: Multiplayer Duplicated Local Player On Spawn - #7 by Marcel_Wiessler1 and it states the following:

“

  1. Init scene that has SceneSwitcher and Networking component for localhost

  2. MainMenu scene that has GUI with a button that calls goToScene to Multiplayer scene

  3. Multiplayer scene that has Synced Room, Player Sync, Spawn Spot Handler similar to Multipalyer Player Sample and a GUI with a button that calls goToScene to MainMenuScene. The network player prefab is based on the Multiplayer Player Sample player prefab with a PlayerMovement, PlayerState, Synced Transform

My test url has a parameter room=needle258.

”

My Main Scene’s objects are only content and the component mentioned earlier.

Thank you for your time.