Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity Multiplayer A quick question with Unity Networking and servers

Discussion in 'Multiplayer Networking' started by TwisterLord, May 17, 2018.

  1. TwisterLord

    TwisterLord

    Joined:
    Aug 5, 2016
    Posts:
    4
    Hello! I'm relatively new to networking, but I have recently thought about making a new game multiplayer. I can deal with learning everything required with making networking compatible and such, but I just have one problem which I cannot fix: Finance.

    Unity provides a feature to host on their own master server, but I really don't have any funds to support such a thing. Unity only has the nessicary master server files for the legacy versions, not the new versions, as far as I am aware anyway. Is there any way for me to be able to host my own master server on my own computer?

    Many games also have a feature where the player hosts a server themselves, on their own machine, so if you are willing to help me out with this problem, please do if you would like! I would greatly appreciate it.

    Thank you again!
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    2,243
    Configure port forwarding on your router to send the port(s) used by your game to your computer and you can host your own server on that computer that anyone on the internet running your game client can reach. .

    Generally you wouldn't ask your players to make that kind of configuration change, so for your players to host their own games that are accessible from the Internet you need to use a solution that gets around their firewall. Photon's design has this built in. Unity has their Unity Multiplayer Service which includes network traffic relay services, and you can look into how to set up something called NAT Punch Through.

    You could also look into other network services from 3rd parties that offer similar services. I believe Steam's networking has that built in for example.
     
  3. TwisterLord

    TwisterLord

    Joined:
    Aug 5, 2016
    Posts:
    4
    If I were to use port forwarding, would Unity's multiplayer API still work, or would I have to use some third party?

    If it can work with Unity's API, how would I be able to configure the ports to my own? Do I do it through code or are there some values which can be changed?

    Thanks!
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    2,243
    I'm not understanding your question. The UNet API is the networking code. Unity Multiplayer is an optional service that provides match making and relay functionality for your game, which is intended to reduce or eliminate the need for your own servers. Unity Multiplayer is a pay for what you use service other than while your game is under development.

    Which Unity API are you asking about still working?

    As far as setting your ports, you do that either through code or optionally in the inspector on the network manager component.

    https://docs.unity3d.com/Manual/UNetManager.html
    https://docs.unity3d.com/Manual/UNetManagerHUD.html
    https://docs.unity3d.com/Manual/class-NetworkServer.html
    https://docs.unity3d.com/Manual/class-NetworkClient.html
     
  5. TwisterLord

    TwisterLord

    Joined:
    Aug 5, 2016
    Posts:
    4
    Oh, okay. I see what you're saying about the ports. Also, yes, sorry about getting you confused, but it was the UNet API I was talking about, the one which grants access to stuff like the NetworkManager, NetworkLobbyManager, etc. As you can tell, i'm very new to multiplayer.

    One more thing: If I want the players to be able to host the server themselves, on their own machine, would it just be them configuring port forwarding and then changing the "Network Address" through code (In the NetworkManager)?
     
    Last edited: May 18, 2018 at 10:50 PM
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    2,243
    So as I mentioned the issue with players hosting their own servers is the typical home computer is assigned a private non-routable IP address by their home router (192.168.x.x, 10.x.x.x, etc). These addresses are not addressable across the Internet. The way you would get around that with a server you would set up for your game is by logging into your router and setting port forwarding settings for all ports your game uses, to direct any of those ports to the internal network IP address of your server computer.

    Yeah you could require players to also do that, but this isn't 1996 anymore. Players expect to just be able to open the game and hit a host game button, so you would need to include another solution built into your game for getting around that.

    Again, some solutions include the Unity Multiplayer Service which is specifically made for this, but costs money. You could build from the ground up your own match making / relay service solution and host it yourself, but all traffic for your game will be crossing your own network and server, which probably isn't free to you either, and potentially would cost you as much or more than just paying for Unity's solution. You could connect most players together using a technique called NAT Punch through, but that still requires a server to set up the initial connections (so still costs you money per month most likely) and doesn't work for some network topologies that players may be using. Since your criteria appears to be needing it to be free, I'm not sure what to suggest since nothing is really free.
     
  7. TwisterLord

    TwisterLord

    Joined:
    Aug 5, 2016
    Posts:
    4
    I may not be getting much here, so feel free to correct me if i'm wrong, but a player going and setting up port forwarding and maybe having to tweak the Network Address (Though this might be done through code) shouldn't be much of an issue. Especially because players don't play just to host a server, more so to join one. A couple of games i've played before actually have it where you open some ports, then its ready.