Search Unity

Bug Creating a [GhostComponentVariation] where no data is synced gives errors

Discussion in 'NetCode for ECS' started by PhilSA, May 13, 2021.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Let's say I want to create a ghost component variation for the Translation component, where nothing gets synced:
    Code (CSharp):
    1.  
    2.         [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    3.         public struct Translation_UnSynced
    4.         {
    5.             [GhostField(SendData = false)]
    6.             public float3 Value;
    7.         }
    This results in errors popping up in the console:
    There are no errors if I set SendData to "true". The errors appear to be inoffensive, though, because in the end this does seem to work and make my Translation not get synced
     
    Lukas_Kastern likes this.
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    I think the problem here is that any float requires quantized=true or it will give you an error, so without specifying quantized it will not find a type it can serialize.

    Can you try just leaving the struct empty instead? So something like `public struct Translation_UnSynced{}`. Everything not in the variant struct should not be synchronized so doing that should give you the same result with less typing and less hassle of getting the parameters right.
     
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I did some tests. The error still occurs with all of the following variations (I tested them separately; not all at the same time):
    Code (CSharp):
    1.  
    2.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    3.     public struct TranslationUnSynced
    4.     {
    5.     }
    6.  
    7.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    8.     public struct TranslationUnSynced
    9.     {
    10.         public float3 Value;
    11.     }
    12.  
    13.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    14.     public struct TranslationUnSynced
    15.     {
    16.         [GhostField(SendData = false)]
    17.         public float3 Value;
    18.     }
    19.  
    20.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    21.     public struct TranslationUnSynced
    22.     {
    23.         [GhostField(Quantization = 1, SendData = false)]
    24.         public float3 Value;
    25.     }
    26.  
    27.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    28.     public struct TranslationUnSynced
    29.     {
    30.         [GhostField(Quantization = 1, Composite = false, MaxSmoothingDistance = 1, SendData = false, Smoothing = SmoothingAction.Clamp)]
    31.         public float3 Value;
    32.     }
     
    Last edited: May 15, 2021
  4. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    895
    Hi Phil!
    In 0.6-preview.7 there two issues with ghost component variation that has been fixed in later NetCode version (that actually uses a completely different code-generation system). Both end up reporting an improper/incorrect error.
    That specific error of yours can be easily spotted in Unity.NetCode.Editor.CodeGenerator.InternalGenerateType, where an error is always printed if there are no fields to serialise (that is indeed not correct).
    As you said, the error looks like inoffensive, since the code for the serializer is still generated but nothing is actually synched. However it is then incorrect in the way is handled later (the component should be completely skipped).
     
    PhilSA likes this.