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

Question Requesting Examples for Custom Scene Managers

Discussion in 'Multiplayer' started by ericlmtn, May 14, 2024.

  1. ericlmtn

    ericlmtn

    Joined:
    Feb 22, 2022
    Posts:
    2
    Dear community,

    I'm working on a high school project with Netcode for GameObjects. My game involves a lobby and potentially several "rooms" that players could be placed into to engage one-on-one.

    I looked at several forum posts & scoured the documentation. I understand that I'd need a custom scene manager to accomplish this. However, I don't see any real code examples implementing a custom scene manager.

    Is there anyone who can disclose a sample project or even a sample C# file involving custom scene management for me to study with?

    Your help is greatly appreciated. Thank you.

    Notes: I have looked into UGS Relay & Lobby, but I'm hoping I can stick with NGO all the way to implement this. Game concept is a lobby where players can choose someone they hope to play a game one-on-one with. I have successfully implemented synced movement in one scene but cannot make two clients move to another scene and others staying in the lobby.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,922
    Because they are very specific to a custom need. They are also very challenging to implement - not the kind of thing I would get myself into for a school project.

    That's because you seem to have a conceptual misunderstanding of what a server, lobby and "room" are for. ;)

    In your case the straightforward solution is this:
    • Use the Lobby service to get 2 players to team up
    • Use a host-client implementation where one player is the host and the other joins
    You can add a dedicated (cloud hosted) game server to avoid a client-hosted game where the host has a competitive advantage due to zero latency.

    You may be able to have a Lobby that supports multiple players but where two players can decide to team off as a party and play. I'm not fully aware of the Lobby services but I believe it's possible to spawn off multiple games from a single lobby with only a few players involved in the game.

    Both of the latter options escalate the complexity of the implementation and time it takes to test significantly.


    The compromise solution would be:
    • Use the Lobby service or your own Lobby (everyone joins a given server) for all players
    • You have a single networked game scene
    • Players deciding to play with/against each other are taken to a "free" location someplace outside the origin (0,0,0) but within 5000 units to avoid any rounding errors. This is their arena to play in, which may either already exist in the network scene or you additively load a network scene with the arena content in it (and possibly change the root object's position to match the game's offset).
    • You will have to design the game so that you manage who is playing who and where. Perhaps use NetworkObjectVisibility to ensure players only see the arena they are playing in and will not be affected by players playing in other arenas. You may also have to design safeguard, such as preventing projectiles from leaving an arena and hitting players in another arena. Perhaps it suffices to have arenas layered atop each other if the game is top-down and projectiles are not affected by gravity.

    The whole idea that players have to be in separate scenes is quite often unnecessary. Spatially dividing players and content will work too.

    But here the challenges are to cleanly separate the players and their arenas, and to manage the state within the same server (sort of like sub-serving games within the same server). This may have an impact on bandwidth, but network object visibility helps in that regard.

    Player count ought to be low enought, probably up to 8 or at most 16 players.
     
  3. ericlmtn

    ericlmtn

    Joined:
    Feb 22, 2022
    Posts:
    2
    Thank you for this reply, I love this solution where players are sent to different locations in the scene so they remain separated.

    I'll work on an implementation with an array of potential coordinates for players to engage in. Thank you again and have a nice day.