Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Not spawn Player prefab in Active additive loaded scene

Discussion in 'Netcode for GameObjects' started by WilliamMonrocq, Nov 23, 2022.

  1. WilliamMonrocq

    WilliamMonrocq

    Joined:
    Apr 29, 2021
    Posts:
    3
    Hi,

    I currently have a project which consists of a MainScene with the NetworkManager, and other elements such as a Menu and the PlayerRig (it is an app for Meta Quest 2).

    At start, I search on the local network if a server exists, if not I create one (this part works perfectly).

    After that, I have multiple scenes in which I can teleport to using the menu. Only 1 will be loaded at a time, and I load it additively with the NetworkSceneManager, keeping my MainScene as the active one.

    The project as is works perfectly, but the scenes' lighting is broken so we had to by-pass it as best as we could. Our fix only works for a single additive scene. In case of an app with multiple complex scenes, we don't have a solution so being able to set it as the active scene would help.

    The problem is that the lighting in the additively loaded scene is broken as it should be the active scene. But if I set it as the ActiveScene, and a new player joins, his Player prefab will be spawned in the Active scene which may be destroyed if I switch scene. It also makes the scene in which players spawn inconsistent, so new players may not synch them properly between the MainScene (which is loaded at the beginning, before the server is started) and the other existing scenes.

    My idea on how to fix it would be to not force spawn player prefabs in the active scene, but in my MainScene

    Here are some errors I get when I start a build as host, then editor as client but host already loaded a 2nd scene and made it active.

    InSceneSynchFailed.PNG

    FailSpawn.PNG

    FindRelative.PNG

    Currently working with Unity 2021.3.6f1 URP and netcode 1.1.0
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    402
  3. WilliamMonrocq

    WilliamMonrocq

    Joined:
    Apr 29, 2021
    Posts:
    3
    Thanks for your answer, but I can't use a custom scene management. The goal of the project is to make a template project to simplify the creation of multi-user apps, so making harder to use the In-Scene objects would go against the idea of a simplified creation.

    I wonder if there is a way to spawn PlayerPrefab with another script and not automatically by the NetworkManager ?

    My current need would be to have a "network Active Scene" which is different than the "Lighting Active Scene" Unity has. The MainScene would be the "network active scene" where Players are spawned, even if the "lighting active scene" is another scene loaded with the NetworkSceneManager.
     
  4. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    402
    If you leave Player Prefab blank in the NetworkManager there's no automatic spawning, you can then spawn your own player using player.NetworkObject.SpawnAsPlayerObject(clientId).
     
  5. WilliamMonrocq

    WilliamMonrocq

    Joined:
    Apr 29, 2021
    Posts:
    3
    Did not know about this spawning, but unfortunately it does not solve the problem.

    Even that way, the second player tries to load the player in the Active scene while I am spawning it in my MainScene, which is not the Active Scene, nor a scene loaded through the NetworkSceneManager, it is the first scene in the build and is never unloaded.