Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug Ghost component does not trigger change filter when write the same data

Discussion in 'NetCode for ECS' started by optimise, Oct 2, 2023.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,128
    When the ghost component write the same data like write 1 value to RefRW<FooComponent> every time instead different value each time like 1, 2, 3 and etc, it will fail to trigger change filter which is not the expected behavior. The expected behavior should be like regular component will trigger change filter when the component is set to read & write like RefRW<FooComponent>.
     
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    313
    Hey optimise. If I understand you correctly, this is a limitation of netcode.
    1. We can't (efficiently) record every change version bump for every single ghost chunk, per component, on the server. Tracking this would be costly in both CPU cost, and bandwidth cost.
    2. Thus, the algorithm netcode uses on the client is: Detect a change in component value (from the server), then only bump change version for that chunk if the value was actually modified.
    I.e. We expected users to mostly want to know when ghosts on the clients were updated with a changed value. We can't track false positive writes.
     
  3. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    892
    Thus, given that expectation, the previous implementation we had was more correct, because you actually pretend there are changes all the time. What you are asking is probagating the information that the server touched a component to the client. That can be possible, but requires a complete different concept (you just want to know if the server wrote on a component). Or better, you just expect that as soon as new data from server this actually change the value, because that is what you are asking.
     
  4. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,128
    I see. Technically I no need exact same regular component change filter behavior that will trigger change filter when the component is set to read & write but I would like netcode still able to trigger change filter even I keep writing the same value to ghost component still treat it as new changes like fooComponent.ValueRW.value = 1 that previously set to 1 and now still set to same 1 value will still trigger change filter. Currently I need to purposely add another data field like version with [GhostField] and bump the version value every time when I write the same value to make sure netcode able to treat it as new changes which is not really nice solution and also wasting bandwidth. Will official able to make ghost component able to auto bump change version even keep writing the same value? If cannot, can official create a ghost component api like fooComponent.BumpVersion() to make it able to trigger change filter?
     
    Last edited: Oct 2, 2023
  5. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    313
    Correct, your approach is the only way to get updates about the server writing to this component but without actually modifying any GhostField values. FWIW: It'll be delta compressed extremely well.

    Note that due to our network model being "eventual consistency", there is a chance that:
    1. Server bumps the value.
    2. Client does not receive (due to other ghosts having higher importance).
    3. Server bumps the value again.
    4. Client receives an update where the version was bumped twice.
    This would be almost identical to what you're currently doing via a BumpVersion byte, so no, unfortunately I wouldn't expect us to support this via a new API.

    Note that - before change filtering was applied - netcode would report that a GhostField component changed every single Simulation step. Therefore, using [GhostField] byte BumpVersion (along with the new change filtering fix) should lead to better filtering than you had previously (at the cost of a small amount of bandwidth).
     
  6. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,128
    Thanks for clarify. Btw how netcode handle ghost dynamic buffer? Is that when ghost dynamic buffer increase count or decrease count or clear the entire dynamic buffer will trigger change filter regardless of the value of the data add into ghost dynamic buffer?
     
  7. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    892
    For buffers, if the count change, we consider the buffer changed. Otherwise, if any of the element inside is changed, we consider the buffer has changed.
     
    Richay and optimise like this.