Search Unity

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

Question How to make entity LocalTransform do not Interpolate when change parent or set parent

Discussion in 'NetCode for ECS' started by hxhloveunity, Oct 27, 2023.

  1. hxhloveunity


    May 27, 2022
    We need to use ghost interpolation for LocalTransform in normal cases.

    When the ghost parent changes, we need to calculate and set a new LocalTransform. In the client, when we also change this ghost's parent, the LocalTransform is interpolated incorrectly, causing a mistake.

    How to avoid this error?
  2. CMarastoni


    Unity Technologies

    Mar 18, 2020
    The parenting is not supported out of the box and indeed that can cause a problem, because it is done by interpolating the local position.
    Instead that should be done in world space and then the local transform re-calculated to have that working as expected.

    There is also another problem: dependency. I order to this work as expected, the parents need to be updated first and then the children.

    That requires a different way to handle to the whole ghost update system for transforms (that does not take into account the parenting information). This is one of (if not the only one) case where a property value depend on the parent property value.

    There are potentially two way to fix this:
    1) Changing what we serialise. Instead of sending the LocalTransform, you implement you own world position component that track the world position of the entity and serialise that instead (and the parent entity too). Then a system on the client will reconstruct the local position starting from this replicated world ones. Because world position tend to remain coherent (even if a parent change) delta compression works quite well. On the contrary, changing the parent may affect largely the local transform (depending on the parent) and indeed may have different compression characteristics, not to speak the baseline prediction can have hard time figuring out a predicted value that minimise the bits that need to be sent.

    2) Another idea could be to set all transform for this specific ghost archetype to be not interpolated.
    Then implement a system that run after the ghost update system and that calculate the interpolated positions using world transform and re-calculate the local transforms accordingly.
    hxhloveunity likes this.