docs.unity3d.com
    Show / Hide Table of Contents

    Class GhostFieldSubType

    Hold a list of constant int that can be used across the project to specify subtype in GhostFieldAttribute. User can expand that list by using an AssemblyDefinitionReference to Unity.NetCode.Gen and adding a partial class that extend and add new constant literals to that class.

    Inheritance
    Object
    GhostFieldSubType
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.NetCode
    Syntax
    public static class GhostFieldSubType
    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 runtime assembly 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 dll before any dependent dll is compiled. Although it does, and Unity.NetCode.dll contains the correct metadata, the ILPostProcessorRunner run 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 it 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 it uses instead and users can add new const literals.

    Why the AssemblyDefinitionReference? Using source generator to add a partial class directly to NetCode.dll works fine but unfortunately will miss the IDE auto-completion functionality. No IDE at the moment provide support for that out of the box. VS has some workaround for normal C# projects (removing the original file from the solution 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.

    Fields

    None

    The default value for the SubType.

    Declaration
    public const int None = 0
    Field Value
    Type Description
    Int32
    In This Article
    • Fields
      • None
    Back to top
    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