Search Unity

What is the maximum (safe) number of variables that a MessageBase Message can contain?

Discussion in 'Multiplayer' started by PhoenixAdvanced, Apr 12, 2021.

  1. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Hello,

    I am working on a game with multiplayer functionality, and I am trying to figure out the best way to save/load the game state to the server when the user ends the game.

    I have a lot of variables to save, so, I have two options:

    Send several messages to the server with a delay in between, or
    Send one large message with a lot of (several dozen) variables.

    I am very concerned about running into some kind of hard limit, particularly if the user has an unreliable internet connection, resulting in the save not completing.

    Note, I am only doing this save/load operation once, at the beginning and end of the play session, and optionally every 5-10 minutes if the player has "autosave" turned on.

    I am using UNET, and I have "packet fragmentation" turned on, so, based on this link:

    https://docs.unity3d.com/2017.4/Doc...working.ChannelOption.AllowFragmentation.html

    my limit should be 64k, which would be 64000 bytes. Since a float is 4 bytes, I should be able to send, theoretically, 16,000 floats, which of course, is far, far more than I will need.

    Therefore, if I am correct, I can use a single large message to send several dozen variables to save/load the game.

    Is this correct? Or is there another hard limit somewhere waiting to byte me?

    Thanks for any advice!
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    My experience is some Internet providers drop all UDP packets above a UDP payload size of 508 bytes, or 576 byte packet size. (508 + 8 UDP header + 60 IP header), because they are allowed to drop all of them. At 576 packet size or lower they are required to make a best effort to deliver the packet. It is covered in some RFC somewhere, but I can't remember the specific one. So I would design around that packet size.

    I believe reducing max packet size also reduces the size of a message sent over a fragmented channel with Unet by the same percentage. I also ran into buggy behavior with use of fragmented channels, which are difficult to troubleshoot since it is all within the engine without much exposed to see what the problems are (the reason I eventually dropped Unet).
     
  3. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    That's interesting, thanks for that. Do you have a source (or a search term) where I can learn more about the UDP limit? I can't seem to find anything relevant on google, it just seems to repeat the 64K limit.

    I will eventually have to move from UNET myself, since it's deprecated, but even with a limit of 508 bytes, that's 127 floats, which should be more than enough.
     
  4. dante66

    dante66

    Joined:
    Mar 25, 2014
    Posts:
    8
  5. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316