Search Unity

DOTS NetCode: MMO locations, portals, items

Discussion in 'NetCode for ECS' started by Orimay, Jan 11, 2020.

  1. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    My game's world is presented as a set of locations, connected via portals in a random way. The world may get pretty large and players don't need all the locations loaded at once, as well as all the items or characters on these locations.

    What's the best approach to spawn/despawn locations and their contents? My solution can figure out how far the location is from the player via custom collections, filled upon the portals connections. But the built-in distance checking won't work since it's grid-based.

    How do I present these locations? They are static pieces of the environment, but they may contain pickable items and movable characters. Ghosts? Or should I use some RPC-based approach to load/unload those and everything they have?

    How do I present items? Should they be ghosts? Even if they either lie on a surface or sit in someone's hand?

    How do I handle rare interactions? Levers, gates, chests -- should we use RPCs there? It doesn't seem like the best solution since this way we'll need to loop all the players to let them know a door was opened, but it definitely seems better than a ghost per door since wasting a byte per eight doors just to let everyone know the rare state change hasn't happened seems weird.
     
    Last edited: Jan 11, 2020
  2. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    I wish there were lazy ghosts with no delta compression for cases where something needs its state updated on a rare basis. The ghosts that would appear/disappear on a user-defined distance condition. Something that would let an item on all the clients know it changed the state just now. Just like RPCs do, but bound to ghost entities.
     
  3. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    One more moment.

    We have a building with multiple doors, that have to sync their open/closed state. As far as I can understand, with Ghosts we can only have doors as prefabs, that'll need to spawn on clients, and therefore -- not initially persist there. This would mean, we need to have the doors removed from locations provided to clients, is this correct?

    It would've been awesome to have pre-linked ghosts, such as doors, levers, platforms, elevators so that they weren't managing their spawn (but were managing despawn in case origin gets removed).
     
  4. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Are you talking about spawning / despawning on the client, server or both? I would make each sector a subscene and stream that in / out for everything static. Items spawned on the server will be sent to the clients though, there is no easy way to deal with that until we get a PVS with a concept of visible / hidden ghosts in the netcode.

    Out goal is that ghosts should be usable for everything except control flow (load this level etc), so I would make items ghosts unless there is an issue and you need to optimize / work around some issue before it is fixed in the netcode.

    Once the netcode is done they should also be ghosts, so unless you have problems with it now I would make them ghosts. We will make sure ghosts which do not change are not sent. Going for RPCs also makes it harder to support late-joining.

    We are currently working on pre-spawned ghosts. Right now the plan is that they have to be in entity sub-scenes rather than using ConvertToClientServerEntity since subscenes gives us an easier way to verify that the client and server has the same set of pre-spawned ghosts.
     
    Orimay, Flipps and pal_trefall like this.
  5. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    Thank you very much for the great response!

    I am talking about server-side spawning/despawning. How do I stream those sectors? Not sure I understand how to use subscenes in NetCode and how to stream the data from server to clients other than via ghosts.
    PVS would've been awesome if I could have my scenes as Ghosts! Sadly, there's scenes serialization confusion due to the ghosts serializer being picked by archetype rather than by actual ghost type :(

    PVS would totally fit my needs if it'll be possible to access the ghost's entity as well as the player's one at the same time.

    I think ghosts will work.

    Could you, please, explain a bit how the subscenes can be used in NetCode? Or is that just a plan? Above you mentioned there's an option to stream those.
     
  6. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    I am specifically talking about streaming in static data which does not contain ghosts. I would generally stream them separately on the client and server rather than having server authoritative streaming. The server needs to keep all sectors where any player is loaded, but it only needs collision geometry - not full meshes, textures etc so maybe you do not need streaming at all on the server. On the client you normally only need to stream in what that specific player is seeing, so it should be separate logic.
    For ghosts the server would create the ghosts any player can see and despawn them when no longer visible if required. All clients would get them, they might have the ghosts for a section but not the static geometry loaded - but that is fine as long as they are not predicted on the client since they are not processed (apart from interpolation).
    The first version of prespawned ghosts in subscenes will require that all subscenes containing ghosts are loaded before any client goes in-game.
     
  7. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    I managed to create ghosts for locations They all have the same ghost type, which only replicates location id and position on a client. The client then spawns the location as a child to that ghost by its index. This way, I guess, I'll be able to despawn the locations on their server-side unload. I am still not sure how to stream locations other than via ghosts.
     
  8. pocketpair

    pocketpair

    Joined:
    Jul 7, 2015
    Posts:
    72
    @timjohansson
    Hello, we are also developing Openworld game with netcode.
    We also have faced similar problem, there are too many ghosts(around 6000) but almost of all ghosts are static objects like tree or stone.
    We'd really like to use pre-spawned ghosts.
    Do you have plan when it is released?

     
    Orimay likes this.
  9. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Pre-spawned ghosts in the first version will not solve this as it will not disable sending of data for unchanged ghosts. I don't have a timeline for when not sending data will be done. Pre-spawned is scheduled for the next release which should be fairly soon after the next entities release though.
     
    bb8_1 and Orimay like this.