question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NetworkManager tries to sync dynamically created scene

See original GitHub issue

Hello everyone !

I’m just starting to try and implement netcode for my tiny simple game and I’m encountering an issue with a dynamically created scene in the active one (used to make physics predictions).

When a script dynamically creates a scene alongside the active one, the NetworkManager will try to sync it on the server side when a new client connects.

Here is an example with a script attached to an empty object on my active scene (the one that fires when the server is started) :

        void Start()
        {
            Physics2D.simulationMode = SimulationMode2D.Script;

            currentScene = SceneManager.GetActiveScene();
            currentPhysicsScene = currentScene.GetPhysicsScene2D();

            CreateSceneParameters parameters = new CreateSceneParameters(LocalPhysicsMode.Physics2D);
            predictionScene = SceneManager.CreateScene("Prediction", parameters);
            predictionPhysicsScene = predictionScene.GetPhysicsScene2D();

            copyAllObstacles();
        }

I don’t know how I can not sync this scene with the current lib. One easy fix could be to check the path length in \Runtime\SceneManagement\NetworkSceneManager.cs line 1550 like this:

if (scene.path.Length == 0 || ExcludeSceneFromSychronization != null && !ExcludeSceneFromSychronization(scene))
 {
     continue;
 }

I assume that the default behavior would be not wanting to sync the dynamically created scenes.

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Sladixcommented, Jan 16, 2023

Yep, that works ! Fortunately I only have one dummy scene so that workaround works like a charm, thanks !

0reactions
NoelStephensUnitycommented, Jan 17, 2023

Glad to hear it! 👍 I went ahead and added a small section in the NetworkSceneManager documentation about how to do this and will go ahead and close this issue out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using NetworkSceneManager
The NetworkSceneManager is only instantiated when a NetworkManager is started. As a server: Any scene you want synchronized with currently ...
Read more >
NetworkManager.ServerChangeScene & ...
Player1 Starts hosting in Scene 1 then NetworkManager. ... will attempt to spawn all objects on the server to sync them up with...
Read more >
How to sync scene loading for all clients using ...
My NetworkManager has no online and offline scene assigned. No playerPrefab also because it will be added dynamically.
Read more >
Network Manager - Mirror Networking - GitBook
When a server or host is started, the Online Scene is loaded. This then becomes the current network scene. Any clients that connect...
Read more >
COMPLETE Unity Multiplayer Tutorial (Netcode for ... - YouTube
00:00 Getting Started with Unity Multiplayer (Netcode for Game Objects) 02:19 Installing Netcode for Game Objects 03:18 NetworkManager 04:07 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found