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

Initialising a NetworkList on the client without creating network traffic.

Discussion in 'Netcode for GameObjects' started by cerestorm, Aug 27, 2022.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    The game I'm creating is played on a map of varying size, potentially being very big. The server has the world map with each client having their own client map. The client map is in the form on a NetworkList of structs with a struct representing each location. On initialisation of the game the client map location structs are marked hidden with no more location information apart from the x,y map position.

    The way the client map is currently initialised all these structs are sent from the server to the client, which for large maps is very slow and stalls the server on sending. I'm looking for a way to initialise the list on the client-side saving the need to send it from the server.

    The closest I can get to is having the initialisation reversed with the client creating the list and it being sent to the server. This stalls the client rather than the server which is better, but is there a way of initialising the network list without any network traffic at all?
     
    lavagoatGG likes this.
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    If the map is randomly genarated, then the host can send the client a specific seed, and then they will both randomly create the same map.
    If map is predefined the clients can have the map built in the app and then the server only needs to send the coordinates
     
    cerestorm likes this.
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    The world map will be randomly generated by the server but not shared with the client. The client's side map is initially hidden with no location data and then revealed by the server as the player moves across the map.

    I've been side-tracked but if there's no better option I'll see how I fair initialising the map from the client. There are other options outside of a network list but I'm trying to be consistent and don't want to special case this one problem with RPC's for example.
     
    lavagoatGG likes this.
  4. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    Just as a followup I was able to get this working as needed. It's possible for the client and server to add to the network list of an object and then call ResetDirty() on the network list so no changes are sync'ed. The only caveat with the server is the object has to be spawned and observed by the client before adding to the list.

    As a more extreme example I added a million structs to each list to draw a 1000x1000 tilemap which was initialised and drawn in a few seconds. There didn't appear to be any significant overhead on later delta changes made to the list by the server.
     
    lavagoatGG likes this.