docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct GhostCount

    Singleton component with APIs and collections required for Ghost counting.

    Implements
    IComponentData
    IQueryTypeParameter
    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.NetCode
    Assembly: Unity.NetCode.dll
    Syntax
    [BurstCompile]
    public struct GhostCount : IComponentData, IQueryTypeParameter

    Properties

    GhostCountInstantiatedOnClient

    The total number of relevant (to our connection) ghosts that the client has actually instantiated (but skips/ignores PendingSpawnPlaceholder ghost instances). Count is updated any time a finalized ghost is actually instantiated or destroyed (via the GhostSpawnSystemGroup).
    Zero if IsCreated is false. Use this with GhostCountOnServer to figure out how much of the state the client has received.

    Declaration
    public int GhostCountInstantiatedOnClient { get; }
    Property Value
    Type Description
    int
    Remarks

    Note: If the relevant set suddenly changes - or the server destroys many ghosts within a single frame - it's possible to have more ghosts on the client than the client should have.

    See Also
    InstantiatedPercent
    GhostCountReceivedOnClient

    GhostCountOnClient

    The total number of relevant (to our connection) ghosts that the client has received (NOT instantiated!). Count is updated any time a snapshot is received and processed.
    The number of received ghosts can be different from the number of currently spawned ghosts.
    Zero if IsCreated is false. Use this with GhostCountOnServer to figure out how much of the state the client has received.

    Declaration
    [Obsolete("Prefer either GhostCountInstantiatedOnClient or GhostCountReceivedOnClient, as this variable is ambiguous (and maps to GhostCountReceivedOnClient). RemoveAfter 1.x.", false)]
    public int GhostCountOnClient { get; }
    Property Value
    Type Description
    int
    Remarks

    Note: If the relevant set suddenly changes - or the server destroys many ghosts within a single frame - it's possible to have more ghosts on the client than the client should have.

    See Also
    ReceivedPercent
    GhostCountInstantiatedOnClient

    GhostCountOnServer

    The total number of relevant (to our connection) ghosts that the server wishes to send this client. Sent in each snapshot, thus count is updated whenever a snapshot was received.

    Declaration
    public int GhostCountOnServer { get; }
    Property Value
    Type Description
    int
    See Also
    InstantiatedPercent
    ReceivedPercent

    GhostCountReceivedOnClient

    The total number of relevant (to our connection) ghosts that the client has received (NOT instantiated!). Count is updated any time a snapshot is received and processed.
    The number of received ghosts can be different from the number of currently spawned ghosts.
    Zero if IsCreated is false. Use this with GhostCountOnServer to figure out how much of the state the client has received.

    Declaration
    public int GhostCountReceivedOnClient { get; }
    Property Value
    Type Description
    int
    Remarks

    Note: If the relevant set suddenly changes - or the server destroys many ghosts within a single frame - it's possible to have more ghosts on the client than the client should have.

    See Also
    ReceivedPercent
    GhostCountInstantiatedOnClient

    InstantiatedPercent

    Denotes the percentage of ghosts instantiated on the client (GhostCountInstantiatedOnClient) versus the number of ghosts the server has said exist (i.e. GhostCountOnServer).
    Only counts relevant ghosts!
    0% when no ghosts are expected: I.e. No ghosts spawned on server, or no ghosts considered relevant, or if this struct is not initialized (i.e. when IsCreated is false). Distinct from ReceivedPercent!

    Declaration
    public float InstantiatedPercent { get; }
    Property Value
    Type Description
    float
    Remarks

    Note: If the relevant set suddenly changes - or the server destroys many ghosts within a single frame - it's possible to have more ghosts on the client than the client should have. Therefore, this value can be greater than 100%.
    Also note: Due to above nuances, it's possible to have the correct count of ghosts, but it's the incorrect set. In other words: This percentage is a naive approximation of 'the client has replicated everything they need'.

    IsCreated

    Helper denoting if the values are valid.

    Declaration
    public bool IsCreated { get; }
    Property Value
    Type Description
    bool

    ReceivedPercent

    Denotes the percentage of ghosts received by the client (GhostCountReceivedOnClient) versus the number of ghosts the server has said exist (i.e. GhostCountOnServer).
    Only counts relevant ghosts!
    0% when no ghosts are expected: I.e. No ghosts spawned on server, or no ghosts considered relevant, or if this struct is not initialized (i.e. when IsCreated is false). Distinct from InstantiatedPercent!

    Declaration
    public float ReceivedPercent { get; }
    Property Value
    Type Description
    float
    Remarks

    Note: If the relevant set suddenly changes - or the server destroys many ghosts within a single frame - it's possible to have more ghosts on the client than the client should have. Therefore, this value can be greater than 100%.
    Also note: Due to above nuances, it's possible to have the correct count of ghosts, but it's the incorrect set. In other words: This percentage is a naive approximation of 'the client has replicated everything they need'.

    Methods

    ToFixedString()

    For debugging and logging.

    Declaration
    public FixedString128Bytes ToFixedString()
    Returns
    Type Description
    FixedString128Bytes

    Logs GhostCount[received:GhostCountReceivedOnClient %, inst:GhostCountInstantiatedOnClient %, server:GhostCountOnServer].

    Implements

    Unity.Entities.IComponentData
    Unity.Entities.IQueryTypeParameter
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)