Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using Netcode for Asymmetric multiplayer with multiple scenes

Discussion in 'Netcode for GameObjects' started by Ethan722, Apr 18, 2023.

  1. Ethan722

    Ethan722

    Joined:
    Sep 23, 2017
    Posts:
    6
    So the setup is I'm working on a college project and we have two different types of player, hide-and-seek-style, we also have multiple scenes that the players will travel through and different players can be in different scenes and will only be visible to each other when in the same scene, and the players will use a different prefab when viewed from their own perspective compared to any other player's perspective. So all around very complicated. Is it possible to do this with a network manager in each of the scenes which carries over between scenes, or does there need to be a server scene which is run separately, and client scenes which house the actual game? Are there any particular design decisions that I should be warry of?
     
    JayHuangYC likes this.
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    Take a look into using your own custom scene management which will give you the flexibility of allowing clients to be in different scenes, but you'll need to have the server manage putting the clients in the right scenes and which game objects to show to them.

    The server (you can't realistically have a host) will sit in a single scene for the duration of the game which contains the game objects for all clients and does all the event handling and client scene management from there.

    Implementing your own scene management isn't that straight forward so be sure the built-in scene management won't fit your needs before going down that route.
     
    Ethan722 likes this.
  3. Ethan722

    Ethan722

    Joined:
    Sep 23, 2017
    Posts:
    6
    As this is for a school project which does not necessitate a dedicated server application, I'm going to try for as long as possible to avoid making one, and in that pursuit I am working with ClientNetworkTransform, but certain objects need to be able to be moved by either the client or the host or another client, how do I make it so that these objects can switch authority, what is the equivalent to "NetworkIdentity.AssignClientAuthority()" in Netcode?
     
    JayHuangYC likes this.
  4. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    You can use NetworkObject.ChangeOwnership(clientId) to grant ownership, there's more useful info in the NetworkObject documentation.
     
    Ethan722 likes this.
  5. Ethan722

    Ethan722

    Joined:
    Sep 23, 2017
    Posts:
    6
    Thanks for your help, with that, anonymous serverRPC, and Unity Relay because our school wifi is not lan friendly, we've figured it out, only problem is all the clients have to move to the same scene whenever one of them switches scenes, but that's seems like a sacrifice we're willing to make instead of going through the effort of combining our 5 scenes into one and changing the door mechanics.

    I should additionally ask, though I'm not sure it will turn out to be a problem, if I send a networkmanager message to change the scene on all clients to, "Scene name here" and in one client's project the scene with that name is different but with the same layout (different lighting) as the scene the other clients are switching to, will that the networkmanager care?
     
  6. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    Give it a whirl, see what happens :) If it does work you'll need a separate client project, or maybe you can change the scene name at runtime. Either way forcing systems to fit your workflow doesn't always end well unless you're 100% sure what you change won't have an impact elsewhere.
     
  7. Ethan722

    Ethan722

    Joined:
    Sep 23, 2017
    Posts:
    6
    We have a player avatar selection screen, so I need to know how to modify the playerprefab value in NetworkManager at runtime, I found NetworkManager.NetworkConfig.PlayerPrefab, but if I modify the value of that will it update the prefab across other clients? And if not how do I change the prefab while staying within the default prefab list?
     
  8. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    Are they selecting the avatar before they join or after in some form of lobby?

    If they're selecting it before you can pass in the avatar type in connection approval and select the the correct player prefab there. I've not tried this myself, there's more info in the connection approval documentation.

    If they're selecting the avatar after connecting I would probably send the avatar type in an rpc or use a player owned network variable to represent it. There may be better Unity-orientated ways of doing this though.

    If you were looking to use Unity's Lobby CodeMonkey has a video where he's doing something similar.


    Before you start I'd recommend updating to the latest version of Netcode (1.4.0) especially if you're going the connection approval route. https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@1.4/changelog/CHANGELOG.html