Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Networking solution for RTS with 10,000+ entities.

Discussion in 'Entity Component System' started by MadboyJames, Nov 11, 2019.

  1. MadboyJames

    MadboyJames

    Joined:
    Oct 28, 2017
    Posts:
    262
    I'm working on an RTS, and I'd like to be able to have multiplayer capabilities. Each player can possibly have up to a couple thousand units which need to be communicated across a server. A game can have up to 10 players. This is my first networking attempt, and I have no real idea where to start. There are many solution and many opinions. I started with a SmartFoxServer (SFS), but the video documentation is a bit lacking. There are unity project examples in SFS, but I definitely need my hand held through the implementation process for this. So, anyone know of a service that has great documentation and might be able to handle passing loads of data? (I would like to attempt Deterministic Lockstep to try and reduce the amount of serverdata being processed, but again, I would need very thorough documentation on how to implement that).

    TL;DR
    What is a good Massive RTS networking solution?

    Any help, suggestions, and opinions are appreciated.
     
    NotaNaN likes this.
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    The only good way to network a game with this many entities is to rely on complete determinism

    In short; instead this:
    • client commands group of units to move to position A (sends a move command to server)
    • server processes move command and makes units move
    • server sends pos/rot sync messages to all clients for all moving units
    you would have this:
    • client commands group of units to move to position A (sends a move command to server)
    • client makes units move locally
    • server receives move command and forwards it to every other client as well
    • server and all non-owning clients revert their entire world to how it was at the timestamp of the move command (compensates for lag), applies command, and fastforwards back to present while making units move locally
    • because of determinism, both clients and server will have units do the exact same movement, but there will be no need to sync anything except move commands
    So instead of sending 10k positions and rotations every frame over network, you'll be sending one single "I clicked move at that position" message once in a while

    But, if this is your first networking project, you might want to consider something simpler first. There's a reason why it's uncommon to see this sort of scale in online games, and it's not because people haven't thought about it :D

    With that said, DOTS has intentions of being completely deterministic one day, and I'm pretty sure the reason why Unity are putting so much effort on determinism is to make this kind of thing possible
     
    Last edited: Nov 11, 2019
    charleshendry and NotaNaN like this.
  3. MadboyJames

    MadboyJames

    Joined:
    Oct 28, 2017
    Posts:
    262
    Gotcha. Thank you! Do you have any suggestions for a networking service that could be good for someone getting into networking? Regardless of its ability to handle the deterministic commands.
     
  4. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    You'll have to wait for DOTS NetCode to come out. The multiplayer sample shooter game shown at last Unite should come out Soon™ and I'm guessing it'll include a new release of DOTS Netcode. But in the meantime, there's a temporary version publicly available now if you want to look at it: https://github.com/Unity-Technologies/multiplayer

    If you're looking for networking outside of DOTS, it's always been hard to find a good solution. Most asset store solutions are very focused on accessibility to beginners, which is totally fine, but there is always a price to pay in power and versatility
     
    NotaNaN likes this.
  5. MadboyJames

    MadboyJames

    Joined:
    Oct 28, 2017
    Posts:
    262
    Okay, I'll keep a watch on the DOTS NetCode. Thank you!
     
  6. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    979
  7. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    297
    Our friends from Factorio wrote a lot of blog posts about it:
    https://www.google.com/search?q=factorio+multiplayer+blog

    Their multiplayer is working with 200 players :)

    They use:
    1) Complete determinism with desync checks
    2) Two worlds
    a) Server authoritative world (stepped when server sends "inputs" packet)
    b) Client predicted world (based on authoritative world + local client input, few frames ahead of auth world)

    Main advantage using ECS with this solution is that:
    1) Very little MP complexity
    2) Tiny data transfers (user input)
    3) ECS allows easy and safe world copy (when auth world changes)
    4) ECS is not hard to make deterministic (use fixed point and be careful with parallel collections)
     
    NotaNaN likes this.
  8. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    As someone here in the forum lately pointed me to the interesting GDC Vault Talk from a Blizzard Employee about Overwatch and their ECS - they use the same design as OndrejP mentions, but use a different technique for missed input iirc:

    Code (CSharp):
    1. They use:
    2. 1) Complete determinism with desync checks
    3. 2) Two worlds
    4. a) Server authoritative world (stepped when server sends "inputs" packet)
    5. b) Client predicted world (based on authoritative world + local client input, few frames ahead of auth world)

    And this is the actual FF Blog Post Ondrej mentions: FF-302
     
    OndrejP likes this.
  9. stefan-falk

    stefan-falk

    Joined:
    Nov 24, 2019
    Posts:
    15
    So, I've been looking at the NetCode docs (https://docs.unity3d.com/Packages/com.unity.netcode@0.0/manual/getting-started.html) and noticed that in this example, only commands are being sent to the server and the clients simulate those commands on their side.

    Is this a concrete example for what you described:

    ?
     
  10. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    513
    My hope is that if the networking team will start with a shooter netcode example and also generate an RTS networking model. As mentioned they have completely different synchronization models.