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

Question Adding multiplayer feature to an existing game, suggestions?

Discussion in 'Multiplayer' started by SimonJ9, May 10, 2022.

  1. SimonJ9

    SimonJ9

    Joined:
    Feb 5, 2018
    Posts:
    17
    Hello, we have a casual game project and a dedicated server running our rest service. The game has been single player and the rest api is for syncing account data. We are now trying to add some multiplayer features, such as a public area where players can have some real time interactions such as moving around, sharing items etc.

    My thought is to use one of the popular networking solutions, such as Mirror or Photon, to make a headless server build, and run it on the server as a separate service. The server build only takes care of the multiplayer area, so our existing service is not affected. Does that sound like a viable solution?

    I have also looked into the room example from Mirror, but the server build was loading scenes and gameobjects just like the client, which could be extra overheads for the server. I was thinking that the server build has only one lightweight scene that syncs data such as player transforms, without expensive operations such as generating/destroying game objects or loading new scenes, but I could be completely wrong. Any suggestions?
     
  2. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    I found a good free networking solution:
    Fish-Networking (The name is kinda funny, I dont know if it is a joke)

    There is a thread about it in this forum
     
    SimonJ9 likes this.
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    If you build your server in Unity, it will always have some overhead. Loading the scene and running the physics is actually the benefit of running a server right in Unity but the downside is needing more CPU for it. If this is a benefit for you, depends on our requirements.
    In server mode, you can strip a lot of the scene loading. Textures and audio is not needed, e.g. but the physics should usually run and you need to represent all objects that are in the networked scene (so they work). I don't know if the server builds automatically strip assets which are not needed.

    A reasonable variant of this approach may be to run the server on a player's machine, while playing. This is usually referred to as running in host mode.
    It is possible to sync players and actions without using a Unity build as server, which is leaner and cheaper but then the authority of the state is distributed. There is no single instance, which can define the complete world state (everyone gets updates from the others but they are always "late" due to lag).

    Sharing items and so on sounds like a task you'd "monitor" via your backend, if this is about objects that should not be duplicated and actually change owner.
     
  4. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    389
    If you are comfortable with letting players potentially cheat you can let the clients host their own servers as tobiass suggested. Otherwise, you're going to need a dedicated server of some sort.

    Headless builds aren't that expensive and neither are operations involving gameObjects if it's casual interactions.

    Find yourself a networking solution that scales well and the majority of your cost will be the initial RAM from a unity headless build.
     
    SimonJ9 likes this.
  5. SimonJ9

    SimonJ9

    Joined:
    Feb 5, 2018
    Posts:
    17
    Thank you for the reply. These are very helpful information. I've been doing research for a couple of days and I found the server build could be performant if I limit the types of object to be synced. Since we are already running our dedicated server, I would like to let the server host the multiplayer sessions. And yes, the multiplayer actions will be server authorized and implemented on the backend. I was concerned about the server cost because I was not sure how many requests are needed to sync the objects, but then I realized the server build is probably not based on http.