Search Unity

"Setting up a Multiplayer Game From Scratch" tutorial issue

Discussion in 'Multiplayer' started by SavedByZero, Nov 28, 2017.

  1. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Hey all -- I'm jumping into multiplayer networking for the first time ever, so forgive my stumbling. I'm at this point:

    -Create a build by pressing the “Build and Run” button. This will prompt for a name for the executable, enter a name such as “networkTest”
    -A stand-alone player will launch, and show a resolution choice dialogue.
    -Choose the “windowed” checkbox and a lower resolution such as 640x480
    -The stand-alone player will start and show the NetworkManager HUD.
    -Choose “Host” from the menu to start as a host. A player cube should be created
    -Press the arrow keys to move the player cube around a little
    -Switch back to the editor and close the Build Settings dialog.
    -Enter play mode with the play button
    -From the NetworkManagerHUD user interace, choose “LAN Client” to connect to the host as a client
    -There should be two cubes, one for the local player on the host and one for the remote player for this client


    This works fine as-is, but when I build and run on my iPhone instead of my Mac, it doesn't work; the Unity editor version of the game tries to connect to the iPhone version (which I have hosting), but always times out. Why is this? Regardless, the tutorial's failure to explain the clear difference between platform interaction with the simulator is a little annoying.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Have you verified you can connect on the same machine first? (Editor -> Mac Standalone build locally)
     
  3. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    The point is that I don't care about the Mac build; I want to test a build on my iPhone while simultaneously testing in Unity with the play button. MY iPhone build is what replaces the installed PC/Mac build in the tutorial there. The iPhone is the host, and the unity IDE build tries and fails to connect. Same thing happens when I use an android instead of an iPhone.

    In any case, I am trying to make something extremely simple. I want a trivia game with a screen that has either the local player or remote player's score and "strikes" against them displayed. I don't want lobbies or anything crazily complex like that, just the ability to either play solo / host, or connect to some other user as a client.

    I pretty much need the code that hooks up to the fake HUD so I can use the commands on my own, but the unity manual is vague about exactly which commands tie to which of those test HUD buttons.
     
    Last edited: Nov 29, 2017
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Are you supplying the correct IP address of your mobile phone to the Unity IDE when you attempt the connection to it?
     
  5. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Yup, no dice. At this point I'm thinking this isn't the long term way that end users are going to connect to find trivia opponents. The tutorial in question that I'm following spends a lot of energy discussing syncing of object movements, but very little about what replaces "localhost" in the long run.
     
  6. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    If you're using the direct connection method, rather than the relay servers to match up players, then no, it definitely isn't the best method, because even on the same LAN you'll need to know how to find the IP address of the host device for the clients to use (localhost will only work if you run both the host and clients on the same device.)

    If you want to connect players over the internet, you'll need to implement some kind of NAT punch through or set up some kind of master server which lists the IP addresses of currently available games, and even then players hosting the game will need to know how to setup port forwarding on their router to make their game available to other players.

    My apologies if I'm repeating stuff you already know.
     
  7. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    So basically the network manager's Match making utility instead of using the host or client UI? "Create Match" seems to turn me into a host, and "find match" seems to turn another instance into a remote client. Those tools actually did the job after I re-enabled Unity multiplayer services...which I'd done before, so I have no idea why it wasn't working, but anyhow.
     
  8. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    Yes, using the match making service will make it easier to match up players, however it isn't free to use, and requires a Unity subscription to 'go live'.
     
  9. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Oh hell. Good to know, thanks. I'm going to have to tell my client that multiplayer is either local only, or a lot more time and money.

    Question for anyone who knows: another thread I googled suggested that NetworkManager was closely tied to the matchmaker, which means payment. Is there ANYTHING in the NetworkManager class that comes free? Like StartHost / StopHost?
     
    Last edited: Nov 30, 2017
  10. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Update: finally got the first issue resolved by connecting to the specific IP address of the phone. Why that works now didn't work before is unclear, but I did do some rebuilding of my networking class, so I must have cleaned something.

    Is the bottom line here that it's impossible to have ANY multiplayer function without knowing the IP address of your local host's phone, unless you feel like paying for the matchmaking services?

    Also, when I traced the server's local client connection address in a text field for testing on the phone ( netMsg.conn.hostId), it came out as "localClient". Why is this?
     
  11. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Okay, just discovered the NetworkDiscovery class and extended it to return what I need. I guess I *can* have free LAN-based networking without requiring users to type in an IP address.
     
    Munchy2007 likes this.