Noticeable lag with matchmaker as opposed to direct connection. Unavoidable?

I just finished the Merry Fragmas 3.0 tutorial and tried out my game with a friend to see if and how something so simple worked in a real world scenario. It worked much better than I expected and this really made me interested in making more multiplayer games, but the one thing we did notice was that when we played using the matchmaker there was definitive lag in the game. When we tried port forwarding and connecting directly to our IP-address this lag wasn’t there.

I don’t measure the lag anywhere in my game yet and I guess it depends on where the Unity relay server is in relation to us, but the lag was annoying and unwanted when we knew we could avoid it by connecting directly to each other.

  • Does it have to be this way?
  • Is it like this for all online games?
  • I haven’t forwarded a port in probably a decade so I guess all online games these days do something similar? Would these games also have less lag if they allowed for you to connect directly to each other?

Any information is helpful. I haven’t googled this subject much yet. I just tried to find any similar threads related to UNET, but didn’t find any.

I honestly thought that the matchmaker only helped with establishing the initial connection between the clients and after that it functioned like a normal peer to peer game, but I guess I don’t understand it. :slight_smile:

Check out the sticky threads in this forum. For example, basic information can be found here and here.

All traffic of games which have been connected by UNET matchmaking is currently routed over unity relay servers. While this does not mean that there is always significantly more lag, I believe it will still introduce additional lag in many cases.

IMHO, the best solution would be:

  1. Try direct connection, if this fails…
  2. Try NAT punch trough (should work in most cases), if this fails as well…
  3. Use relay servers to guarantee connection in 100% cases

I think it would be nice if this connection logic would be supported by UNET out of the box. Also, I think it would be a good idea to decouple the matchmaking feature and the use of relay servers. You may also look at the improvement thread where such options had been requested since some time. This post indicates that UNET might natively support NAT punch through in the future. In the meantime, you should have a look at this asset.

1 Like

Thanks, for the extensive reply. That cleared it up.

NAT punch through is the term I was after. That was how I thought the matchmaking worked and why I was so puzzled that it introduced extra lag.