Search Unity

Bug (1.0.8) Composite causing Ghost Data to not always sync

Discussion in 'NetCode for ECS' started by tertle, May 12, 2023.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    upload_2023-5-12_20-4-51.png

    Loading up my existing project for some reason my component is not always syncing.
    The pair on the left are syncing fine, the pair on the right are not - they both exist at the same time on the client but only 1 is working.
    The data is just a giant chunk of 512 bytes.

    Code (CSharp):
    1.     [GhostComponent]
    2.     internal struct Packet : IComponentData
    3.     {
    4.         [GhostField(Composite = true)]
    5.         public FixedBytes512 Buffer;
    6.     }
    7.  
    8.     [Serializable]
    9.     public struct FixedBytes512 : IEquatable<FixedBytes512>
    10.     {
    11.         public FixedBytes64 Offset0000;
    12.         public FixedBytes64 Offset0064;
    13.         public FixedBytes64 Offset0128;
    14.         public FixedBytes64 Offset0192;
    15.         public FixedBytes64 Offset0256;
    16.         public FixedBytes64 Offset0320;
    17.         public FixedBytes64 Offset0384;
    18.         public FixedBytes64 Offset0448;
    19.  
    20.         public unsafe bool Equals(FixedBytes512 other)
    21.         {
    22.             fixed (void* ptr = &this)
    23.             {
    24.                 return UnsafeUtility.MemCmp(ptr, &other, sizeof(FixedBytes512)) == 0;
    25.             }
    26.         }
    27.  
    28.         public override int GetHashCode()
    29.         {
    30.             return (int)math.hash(math.hashwide(new int4x2(
    31.                 new int4(this.Offset0000.GetHashCode(), this.Offset0064.GetHashCode(), this.Offset0128.GetHashCode(), this.Offset0192.GetHashCode()),
    32.                 new int4(this.Offset0256.GetHashCode(), this.Offset0320.GetHashCode(), this.Offset0384.GetHashCode(), this.Offset0448.GetHashCode()))));
    33.         }
    34.     }
    35.  
    36.     [Serializable]
    37.     public struct FixedBytes64 : IEquatable<FixedBytes64>
    38.     {
    39.         public long Offset00;
    40.         public long Offset08;
    41.         public long Offset16;
    42.         public long Offset24;
    43.         public long Offset32;
    44.         public long Offset40;
    45.         public long Offset48;
    46.         public long Offset56;
    47.  
    48.         public unsafe bool Equals(FixedBytes64 other)
    49.         {
    50.             fixed (void* ptr = &this)
    51.             {
    52.                 return UnsafeUtility.MemCmp(ptr, &other, sizeof(FixedBytes64)) == 0;
    53.             }
    54.         }
    55.  
    56.         public override int GetHashCode()
    57.         {
    58.             return (int)math.hash(math.hashwide(UnsafeUtility.As<FixedBytes64, int4x4>(ref this)));
    59.         }
    60.     }

    If I make Composite=false it work fine.
     
    Last edited: May 12, 2023
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    316
    Hey Turtle,
    Thanks for the report. The team did some work recently with regards to Composite, I'll see if I can see why this is happening. Looks like our test coverage needs to be expanded too.
    Can you file it as a Unity bug, for tracking purposes? Cheers.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    IN-40905
     
    NikiWalker likes this.
  4. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    316
    Yep, the CalculateChangeMask code-generation for Packet is just completely wrong here. In the generated file Temp/NetcodeGenerated/[YourFolderStructure]/PacketSerializer.cs, method CalculateChangeMask roughly on line 826. We clobber the changemask every 64 bytes.

    Note: You may need to modify your .globalConfig in your project root to enable:
    # enabe/disable the Netcode source generator files output in the temp folder. 0 disable, empty or 1 enable.
    unity.netcode.sourcegenerator.write_files_to_disk=1


    We'll get this fixed, but yeah please use your workaround for now.
     
    tertle likes this.