Search Unity

Resolved Error when connecting to Relay as client w/ NGO

Discussion in 'Relay' started by Nevey, Dec 16, 2021.

Thread Status:
Not open for further replies.
  1. Nevey

    Nevey

    Joined:
    Nov 23, 2012
    Posts:
    6
    Hi all,

    In my flow, I'm creating a lobby, player 2 joins and once that happens the lobby host will allocate a relay server and via lobby I'm sharing the joinCode and letting player 2 join the relay server via this joinCode.

    All seems to work fine except the client (player 2) is trying to load a scene that's already active:

    Exception: Failed to find any loaded scene named GameplayScene!


    Now I debugged the code where S*** hits the fan and it seems not all cases are covered, it's throwing an exception in the snippet below in file ```NetworkSceneManager, line 641```.

    Code (CSharp):
    1. internal Scene GetAndAddNewlyLoadedSceneByName(string sceneName)
    2. {
    3.     for (int i = 0; i < SceneManager.sceneCount; i++)
    4.     {
    5.         var sceneLoaded = SceneManager.GetSceneAt(i);
    6.         if (sceneLoaded.name == sceneName)
    7.         {
    8.             if (!ScenesLoaded.ContainsKey(sceneLoaded.handle))
    9.             {
    10.                 ScenesLoaded.Add(sceneLoaded.handle, sceneLoaded);
    11.                 return sceneLoaded;
    12.             }
    13.         }
    14.     }
    15.  
    16.     throw new Exception($"Failed to find any loaded scene named {sceneName}!");
    17. }
    I learned that
    if (!ScenesLoaded.ContainsKey(sceneLoaded.handle))
    will always be
    true
    in my case. The
    ScenesLoaded
    dictionary already contains the scene it's trying to load and thus will automatically end up in the exception being thrown.

    It seems like a bug to me, if so I'll report it properly. But any way I can work around this? I don't need help loading correct scenes or anything, which this code states to be doing:

    /// Since SceneManager.GetSceneByName only returns the first scene that matches the name
    /// we must "find" a newly added scene by looking through all loaded scenes and determining
    /// which scene with the same name has not yet been loaded.
    /// In order to support loading the same additive scene within in-scene placed NetworkObjects,
    /// we must do this to be able to soft synchronize the "right version" of the NetworkObject.


    To be clear: I'm NOT spawning a PlayerPrefab from the NetworkManager as I'm not looking to do this anyway (might need to change my setup to UDP instead of NGO?). I'm also not sending any RPCs yet or doing any other kind of networked activity yet.

    It's kinda blocking me to continue this project. And I'm starting to seriously consider other non-unity networking solutions (I know Relay is in Beta, but I also wanna make progress :) )

    Running this on Unity 2021.2.3f1 and using the following package versions:
    upload_2021-12-16_12-26-56.png

    Cheers!
     
  2. UnityKip

    UnityKip

    Unity Technologies

    Joined:
    Nov 15, 2021
    Posts:
    36
    Hi Nevey,

    Thank you for participating in the Lobby and Relay beta.

    Before we get too far into troubleshooting, it may not be possible for me to provide a workaround to your issue without seeing your project directly. If we need any private information (such as a ProjectID or a build) for analysis then I'd encourage you to open a Help Ticket through your Unity Dashboard -> Help & Support -> File a Ticket -> Multiplayer -> Relay for further troubleshooting.

    From what you've described, this may be a bug in the SDK. I'll need to reproduce the issue locally to raise it with engineering. If the project is small enough, you may be able to DM your relevant code over or post the call stack to facilitate this. You can also submit the issue on your own here. If you do submit your own issue, please reply to this post with the link to the issue and I'll follow up on it as well.

    Without confirming the bug or seeing your code, my suggestion would be to remove GameplayScene from SceneManager when your client is transitioning between scenes using Unity.Netcode.NetworkSceneManager.UnloadScene(Scene scene).

    Note that this is a completely temporary solution intended to allow you to continue development while a long-term fix is determined.

    Finally, it is possible that the issue you're seeing is caused by Relay, however, I suspect it's an edge-case in Netcode for GameObjects. I'd like to keep this post here for now, but may move it to another board if Relay is found to be irrelevant to the issue.

    Let me know if you have any further questions or concerns and if the workaround is viable for your continued development while we investigate.

    Regards,
    -Kip
     
  3. Nevey

    Nevey

    Joined:
    Nov 23, 2012
    Posts:
    6
    Hi Kip,

    Thanks for the extensive response. Before you posted this I've changed from NGO to UDP as it'd fit my needs better for this specific project anyway. And I'm not running into any issues so far. Lobby and Relay seem to be doing their jobs just fine.

    But good to know there's a workaround for the NGO issue I happened to run in to.

    Cheers!

    P.S. The reason I've posted this here and not started a ticket is because other devs might run in to this same issue. Now the web knows and it's workaround ;)
     
  4. UnityKip

    UnityKip

    Unity Technologies

    Joined:
    Nov 15, 2021
    Posts:
    36
    Glad to hear that it you were able to work out a solution on your end.

    This is the way. Thank you from the future.

    Let us know if anything else comes up and best of luck out there!
    -Kip
     
  5. emilyryan

    emilyryan

    Unity Technologies

    Joined:
    Nov 22, 2019
    Posts:
    129
    We're going to close out this forum thread, but please feel free to make a new forum post if you have any follow up questions. Thanks for your time!
     
Thread Status:
Not open for further replies.