Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Discussion Looking for Advice - Multiple server worlds or filtering everything by teams

Discussion in 'NetCode for ECS' started by FootSteps, Aug 10, 2022.

  1. FootSteps

    FootSteps

    Joined:
    Aug 19, 2014
    Posts:
    12
    This is my first attempt at using Netcode for Entities. I currently have 1+ clients connecting to a server playing a Tower Defense type game. Each client currently can see the towers, enemies, and attacks. This is great.

    For the next milestone I'm shooting for in my game is multiple teams. What I have now is 1 teams base / gameplay loop. I need to replicate this for additional teams.

    Never at any point will more than 1 team be shown on a clients screen. They click a button to `Spectate` the other team, losing sight of their own. The only interaction between the teams, is sending a small amount of data to send enemies at the other team and maybe showing team scores to other clients.

    So in my mind I have two different solutions going forward.

    1. Create a separate server world for each team, if possible put them on separate network ports. So each team would be playing in a server world like ServerWorld_TeamX with X being each teams index. Seems like a little bit of code, and I can duplicate what I have already as additional teams.

    2. Create a TeamID filter component for all entities. Every tower, enemy, and environment will have a TeamID. Use Ghost Relevancy to separate what data is sent to each client based on TeamID. So each client will only be viewing / commanding their own TeamID filtered entities. With the option of viewing another TeamID as a spectator.

    I'm going to attempt Option 1 first. Unless this thread gets some responses with real world advice / examples. In my mind option 1 is much cleaner and simpler, but unsure if there are internal limitations on the server connections or something else I'm missing. Option 2 seems alot dirtier and alot more work, but maybe doing all the processing together this way with a filter is more performant? At some point I read there is a component type I can use that chunks all entities together with the same TeamID. So maybe that is the way to go.

    Anyway, thanks for reading / rubber ducking / providing support. I will post feedback on what I'm doing when I figure out what I'm doing.

    Thanks,

    FootSteps

    EDIT 1--- 8/10/22 - 1 hour after original post
    Option 1 only took about an hour to implement. Seems to work out of the box, without having to change anything besides additional server worlds by team index, and the server connection listening on a different port in each world. The clients connect to their teams port. With the current workaround of client needs to know what team they are joining before connecting. So they can connect to the correct port, which I'm just increasing the port by the teams index. So a matchmaker or slightly more elegant server solution is needed.

    Here is 4 different teams playing, with a player on team 1 hosting in my editor.

    upload_2022-8-10_17-13-47.png

    Server Worlds added
    upload_2022-8-10_17-14-44.png

    I'm gonna continue with this for now, but I suspect there is additional performance overhead duplicating server worlds.
     
    Last edited: Aug 11, 2022
    kynphlee and Occuros like this.
  2. kynphlee

    kynphlee

    Joined:
    Sep 19, 2022
    Posts:
    2
    Hi, I'm working on a multiplayer ECS project and I was thinking about the concept of managing multiple server worlds, and it seems like curious minds think alike. Have you had any further progress?
     
  3. FootSteps

    FootSteps

    Joined:
    Aug 19, 2014
    Posts:
    12
    Multiple server worlds seems fine at the moment. The only thing is when you try to interact between the worlds, you gotta pay attention to what world / system you are accessing and what entities you are targeting / interacting with. I'm not much further than where I left off as I took a break for quite some time. I'll probably get back into it and post some updates here if I encounter any multiple server world issues.

    Took a break when 1.0 came out, and the documentation / examples were not updated so I couldn't migrate without loads of work figuring things out. I actually did start recently, after I saw the examples were update for netcode. I'm like half done updating to 1.0 hopefully it works first try when I finish and am able to run it again.
     
    kynphlee likes this.