Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

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

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

  1. PhilSA


    Jul 11, 2013
    Let's say I want to create a ghost component variation for the Translation component, where nothing gets synced:
    Code (CSharp):
    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


    Unity Technologies

    Jul 13, 2016
    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


    Jul 11, 2013
    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):
    2.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    3.     public struct TranslationUnSynced
    4.     {
    5.     }
    7.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    8.     public struct TranslationUnSynced
    9.     {
    10.         public float3 Value;
    11.     }
    13.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    14.     public struct TranslationUnSynced
    15.     {
    16.         [GhostField(SendData = false)]
    17.         public float3 Value;
    18.     }
    20.     [GhostComponentVariation(typeof(Unity.Transforms.Translation), "TranslationUnSynced")]
    21.     public struct TranslationUnSynced
    22.     {
    23.         [GhostField(Quantization = 1, SendData = false)]
    24.         public float3 Value;
    25.     }
    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


    Unity Technologies

    Mar 18, 2020
    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.