docs.unity3d.com
    Show / Hide Table of Contents

    Class GhostFieldAttribute

    Inheritance
    Object
    Attribute
    GhostFieldAttribute
    Namespace: Unity.NetCode
    Syntax
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class GhostFieldAttribute : Attribute, _Attribute

    Constructors

    GhostFieldAttribute()

    Declaration
    public GhostFieldAttribute()

    Properties

    Composite

    Only applicable on GhostFieldAttributes applied to a non primitive struct containing multiple fields. If this value is not set (a.k.a. false, the default), a 'change bit' will be included 'per field, for every field inside the nested struct'. There will be no 'change bit' for the struct itself. I.e. If a single field inside the sub-struct changes, only that fields 'change bit' will be set. Otherwise (if this Composite bool is set, a.k.a. true), we instead use a single 'change bit' for 'the entire nested struct'. I.e. If any fields inside the sub-struct change, the single 'change bit' for the entire struct will be set. Check the Serialize/Deserialize code-generated methods in Library\NetCodeGenerated_Backup for examples.

    Declaration
    public bool Composite { get; set; }
    Property Value
    Type Description
    Boolean

    MaxSmoothingDistance

    The maximum distance between two snapshots for which smoothing will be applied. If the value changes more than this between two received snapshots the smoothing action will not be performed.

    Declaration
    public float MaxSmoothingDistance { get; set; }
    Property Value
    Type Description
    Single
    Remarks

    For quaternions the value specified should be sin(theta / 2) - where theta is the maximum angle you want to apply smoothing for.

    Quantization

    Floating point numbers will be multiplied by this number and rounded to an integer, enabling better delta-compression via huffman encoding. Specifying a Quantization is mandatory for floating point numbers and not supported for integer numbers. To send a floating point number unquantized, use 0. Examples: Quantization=0 implies full precision. Quantization=1 implies precision of 1f (i.e. round float values to integers). Quantization=2 implies precision of 0.5f. Quantization=10 implies precision of 0.1f. Quantization=20 implies precision of 0.05f. Quantization=1000 implies precision of 0.001f.

    Declaration
    public int Quantization { get; set; }
    Property Value
    Type Description
    Int32

    SendData

    Default true. If unset (false), instructs code-generation to not include this field in the serialization data. I.e. Do not replicate this field. This is particularly useful for non primitive members (like structs), which will have all fields serialized by default.

    Declaration
    public bool SendData { get; set; }
    Property Value
    Type Description
    Boolean

    Smoothing

    Default is Clamp.

    Declaration
    public SmoothingAction Smoothing { get; set; }
    Property Value
    Type Description
    SmoothingAction

    SubType

    Allows you to specify a custom serializer for this GhostField using the GhostFieldSubType API.

    Declaration
    public int SubType { get; set; }
    Property Value
    Type Description
    Int32
    Remarks

    Why GhostFieldSubType is not an enum: The reason is that there are unfortunately caveats, some due to our compilation pipeline and others due to the limitation of the SourceGenerator api. First: MS SourceGenerator are additive only. That means we cannot modify the syntaxtree, removing or adding nodes to it (not the way Analyzers does). To overcome that limitation, a possible solution to inject the enums literals into the assembly is to use a small IL post processor instead. Because NetCode rutime asssembly is re-imported every time a sub-type is added or removed, the assumption was that the IL post-processing will then correctly modify the the dll before any dependent dll is compiled. Although it does, and Unity.NetCode.dll contains the correct metadata, the ILPostProcessorRunner runt at a later time and some dlls are not compile correctly (depend on timing). With further investigation it might be possible to address that problem, however seems like fighting against the compilation process again, something we wanted to avoid. Because all of that, a partial class to hold the integral constants is used instead and esers can add new const literals.

    Why the AssemblyDefinitionReference? Using source generator to add a partial class diretly to NetCode.dll works fine but unfortunately will miss the IDE auto-completion functionality. No IDE at the moment provide a support for that out of the box. VS has some workaround for normal C# projects (removing the original file from the sulution etc) or by restarting the IDE, but Rider or VSCode does not work the same way. By using the Assembly Definition Reference, we are actually doing in principle the same job and completion works, making the user experience a little more pleasant.

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023