Search Unity

Is it safe to synchronize Entity fields over network?

Discussion in 'NetCode for ECS' started by PhilSA, Feb 12, 2021.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Quick question: does it make sense to sync Entity fields in ghosts over network? Will the same objects be represented by the same Entity ids across all clients/servers?
     
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    It will only work if the entity you reference is a ghost, you cannot synchronize a reference to a non-networked entity even if you know it exists on both the client and server.

    It is also a weak-reference, it is guaranteed to be the correct entity if it is resolved to a valid entity, but it can in some corner cases be resolved to Entity.Null even if the reference is set.
    The order the ghosts are spawned is also not guaranteed so you need to handle the cases where the ref only exist on either the client or the server.
    I think it currently also fails resolving when the entity exists on the receiving side for 1 or a few frames on despawn - but that might change to fail in more of fewer cases.
     
    Wokky and PhilSA like this.
  3. skiplist

    skiplist

    Joined:
    Nov 9, 2014
    Posts:
    46
    The main problem I have had is that the reference stays Null after the ghost has been spawned on the client so you kind of have to bump something in the same entity to make it appear. Some way to force this manually or even better not ack these fields when they fail to lookup the ghost on the client would help :)