Search Unity

Resolved Snapshot not sending child rotation for interpolated entity

Discussion in 'NetCode for ECS' started by GameDeveloper1111, Oct 16, 2021.

  1. GameDeveloper1111

    GameDeveloper1111

    Joined:
    Jul 24, 2020
    Posts:
    100
    Edit:

    Resolved:

    Solution:

    Code (CSharp):
    1. overrides["Unity.Transforms.Rotation"].attribute.SendDataForChildEntity = true;
    See source for more information:

    ---

    Original post:

    ---

    Goal:

    I'm trying to present a ghost child entity (blue) of a client-interpolated ghost (red), but the server rotation data of the ghost child entity is not transferring to the client-side ghost child entity, despite the translation data of the ghost root entity transferring.

    upload_2021-10-15_21-53-46.png

    The ghost has no ghost owner and is in interpolation-only mode; i.e. there is no prediction or player input involved.

    upload_2021-10-15_21-53-55.png

    I've attached a minimal example .zip to this post. It's based on https://github.com/Unity-Technologies/multiplayer/tree/master/sampleproject/Assets/Samples/NetCube

    Here is a visualization of the goal:

    Red: Ghost root entity
    Blue: Ghost child entity

    2021-10-15 21-25-45-small.gif

    Here is the current state of things:

    2021-10-15 21-25-45-no-rotation-small.gif

    Here is the server update system:

    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.NetCode;
    3. using Unity.Transforms;
    4. using Unity.Mathematics;
    5.  
    6. [UpdateInWorld(UpdateInWorld.TargetWorld.Server)]
    7. [UpdateInGroup(typeof(GhostSimulationSystemGroup))]
    8. public class MoveCubeSystem : SystemBase
    9. {
    10.     protected override void OnCreate()
    11.     {
    12.     }
    13.  
    14.     protected override void OnUpdate()
    15.     {
    16.         float elapsedTime = (float)Time.ElapsedTime;
    17.  
    18.         Entities
    19.             .ForEach((
    20.                     Entity               entity,
    21.                 ref Translation          translation,
    22.                 ref MovableCubeComponent movableCubeComponent
    23.                 ) =>
    24.         {
    25.             // Translate cube (entity root) via time
    26.             translation.Value.z += 0.05f * math.sin(elapsedTime * 2.5f);
    27.  
    28.             // Rotate child entity via time
    29.             // NOTE: This data does not transfer to the client for some reason
    30.             var childRotation = GetComponent<Rotation>(movableCubeComponent.ChildEntity);
    31.             childRotation.Value = quaternion.Euler(0f, math.radians(movableCubeComponent.RotationSpeed * elapsedTime), 0f);
    32.             SetComponent(movableCubeComponent.ChildEntity, childRotation);
    33.         }).Run();
    34.     }
    35. }
    36.  
    To get the goal visualization video I ran this system on the client as well.

    The Entities window in the Editor shows that the child's rotation in the server world is updating while the child's rotation in the client world is not, despite the translation of the root entity in each world updating. The child entity has a `GhostChildEntityComponent`.
     

    Attached Files:

    Last edited: Oct 16, 2021
    Krooq likes this.
  2. GameDeveloper1111

    GameDeveloper1111

    Joined:
    Jul 24, 2020
    Posts:
    100
    Below are screenshots showing that there exists a non-zero rotation on the server, but a zero rotation on the client, despite the translations matching (in LocalToWorld):

    ServerWorld:


    upload_2021-10-15_22-5-44.png

    ClientWorld0:

    upload_2021-10-15_22-5-10.png

    Correlation: I did not have this child-entity-not-updating problem for interpolated ghosts when I had a corresponding ghost-owner-predicted ghost in another client world and ran updates for it in the server's GhostPredictionSystemGroup.
     
    Last edited: Oct 16, 2021
  3. GameDeveloper1111

    GameDeveloper1111

    Joined:
    Jul 24, 2020
    Posts:
    100
    This looks interesting. Will try.

    Edit: It worked.
     
    Last edited: Oct 16, 2021
  4. ChrisPie

    ChrisPie

    Joined:
    Mar 5, 2015
    Posts:
    31
    Keep in mind IGhostDefaultOverridesModifier will be deprecated soon (or even removed in next version). So this is not a future-proof solution. What you should be doing is setting the flag in the component list of the prefab. If the checkboxes are greyed out, there's a temporary fix somewhere on the forums. Even with that fix, you'll need another fix from here:
    https://forum.unity.com/threads/ind...amicbuffer-of-29-length.1160462/#post-7541482
    to have the child override actually saved in the prefab. 0.6 buggy is enough that I regret using NetCode so soon.
     
    GameDeveloper1111 likes this.