Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Addressable Scene sync in NetCode Multiplayer

Discussion in 'Multiplayer' started by Bobane, May 11, 2024.

  1. Bobane

    Bobane

    Joined:
    May 13, 2014
    Posts:
    17
    I am getting this error when I build my game and try to start the host from the build. This does not happen in the editor. I use addresasbles and don’t have any duplicate assets when i run the analyzing tool. All my scriptable objects are addressable, my scenes, my prefabs. My Network Manager is not an addressable , is this the problem? should it be?


    NetworkManager.Singleton.StartHost(); - An item with the same key has already been added Key: -1
     
    Last edited: May 12, 2024
  2. Bobane

    Bobane

    Joined:
    May 13, 2014
    Posts:
    17
    This is the code

    Allocation a = await RelayService.Instance.CreateAllocationAsync(maxPlayers);
    joinCode.text = await RelayService.Instance.GetJoinCodeAsync(a.AllocationId);
    transport.Value.SetHostRelayData(a.RelayServer.IpV4, (ushort)a.RelayServer.Port, a.AllocationIdBytes, a.Key, a.ConnectionData);

    NetworkManager.Singleton.StartHost();
    NetworkManager.Singleton.OnClientConnectedCallback += MoveToCardGame;
     
  3. Bobane

    Bobane

    Joined:
    May 13, 2014
    Posts:
    17
    Update; I tried it and thats not it. Is it possible that addressable scenes are just not meant to work with NetCode? As in the automatic scene synchronization, because from what I can see if I make them addressable they are checked off in the build settings, but if i make them Built in they cannot be addressable, totally lost
     
  4. Bobane

    Bobane

    Joined:
    May 13, 2014
    Posts:
    17
    The line that throws it is this
    ```
    at Unity.Netcode.NetworkSceneManager.GenerateScenesInBuild () [0x0005f] in .\Library\PackageCache\com.unity.netcode.gameobjects@1.7.1\Runtime\SceneManagement\NetworkSceneManager.cs:634
    ```
     
  5. Bobane

    Bobane

    Joined:
    May 13, 2014
    Posts:
    17
    So what I got at is that I somehow managed to build the project while my scenes were both set as addressable and in the built in scenes list in the build settings and this was throwing the error. The problem is , when I Start the Host and I have addressable scenes, they are not in the built in scenes so they cannot be loaded , what is the procedure here?
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
  7. Bobane

    Bobane

    Joined:
    May 13, 2014
    Posts:
    17
    Could you point me to the specific area of the manual? It has 1000 lines of code. The issue is that if I have automatic scene synchronization when a client connects, it tries to load the scene from the build settings. Are you suggesting that I should rewrite my architecture to NOT use automatic scene sync in that case and load what has to be loaded via these dynamic prefabs? Or are you suggesting that I keep the auto scene sync in netcode and add code to my existing architecture so that my scenes can be treated as these dynamic prefabs?
     
  8. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    I am suggesting that you read and understand the page because it tells you what you need to do to make addressables work in a networked game. You have several options to do so, pick the one that best suits your situation.
     
  9. Bobane

    Bobane

    Joined:
    May 13, 2014
    Posts:
    17
    Right, thanks for the help but the answer is not there. In NetworkSceneManager.cs 614
    Code (CSharp):
    1.  internal void GenerateScenesInBuild()
    2.         {
    3.             // TODO 2023: We could support addressable or asset bundle scenes by
    4.             // adding a method that would allow users to add scenes to this.
    5.             // The method would be server-side only and require an additional SceneEventType
    6.             // that would be used to notify clients of the added scene. This might need
    7.             // to include information about the addressable or asset bundle (i.e. address to load assets)
    This is the answer to my question - Scene sync in Netcode and Addressables are not compatible, plain and simple, also very bad because that seems like one of the most basic need to haves

    So it seems like the entire architecture has to be re-written because the build is not the editor
     
  10. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    Oh, I see, loading a networked scene from an Addressable. Which version of NGO are you using? I thought addressable scene loading was added recently but perhaps it was more of a "coming soon".