docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct Connection

    Abstraction to interact with an underlying connection. If offline, some of its fields will be invalid.

    Implements
    IEquatable<Connection>
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Netcode
    Assembly: Unity.NetCode.dll
    Syntax
    public struct Connection : IEquatable<Connection>

    Fields

    World

    The world this connection belongs to. A server world will have multiple connections, one for each connected client. All those connections would have their world set to the server world, this is the world the connection lives in.

    Declaration
    public NetcodeWorld World
    Field Value
    Type Description
    NetcodeWorld

    Properties

    ConnectionEntity

    The entity associated with this connection. This is the entity that has the NetworkId component.

    Declaration
    public readonly Entity ConnectionEntity { get; }
    Property Value
    Type Description
    Entity

    NetworkId

    The NetworkId associated with this connection. See NetworkId

    Declaration
    public NetworkId NetworkId { get; }
    Property Value
    Type Description
    NetworkId

    RTT

    Current estimated Round Trip Time for this connection.

    Declaration
    public float RTT { get; }
    Property Value
    Type Description
    float

    Methods

    EnableGhostReplication(bool)

    Dictates which replication behaviour to use for this connection. NetworkStreamInGame By default, replication is enabled for new connections on both the client and the server, this can be changed via the AutomaticStateReplication toggle. Disabling replication limits the connection to RPCs only, and it must be re-enabled on both sides to resume.

    Declaration
    public void EnableGhostReplication(bool enable)
    Parameters
    Type Name Description
    bool enable

    True to enable ghost replication for this connection, false to disable it.

    Equals(object)

    Checks whether the object is a Connection equal to this one.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    The object to compare with.

    Returns
    Type Description
    bool

    True if the object is an equal connection.

    Overrides
    ValueType.Equals(object)

    Equals(Connection)

    Checks whether both connections have the same NetworkId and connection entity.

    Declaration
    public bool Equals(Connection other)
    Parameters
    Type Name Description
    Connection other

    The connection to compare with.

    Returns
    Type Description
    bool

    True if the connections are equal.

    GetConnectionState()

    Returns the ConnectionState.State of the current connection

    Declaration
    public ConnectionState.State GetConnectionState()
    Returns
    Type Description
    ConnectionState.State

    Unknown if the current connection is invalid

    GetHashCode()

    Returns a hash code based on the NetworkId value of this connection.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    The hash code of this connection.

    Overrides
    ValueType.GetHashCode()

    IsValid()

    Whether this Connection struct is initialized and valid. See GetConnectionState() for getting the state of a valid Connection

    Declaration
    public bool IsValid()
    Returns
    Type Description
    bool

    True if the connection has a valid world and an existing connection entity.

    RequestDisconnect(NetworkStreamDisconnectReason)

    Async method to disconnect this connection. See NetworkStreamRequestDisconnect

    Declaration
    public void RequestDisconnect(NetworkStreamDisconnectReason reason = (NetworkStreamDisconnectReason)0)
    Parameters
    Type Name Description
    NetworkStreamDisconnectReason reason

    The reason for the disconnection.

    Operators

    operator ==(Connection, Connection)

    Checks whether two connections are equal. See Equals(Connection).

    Declaration
    public static bool operator ==(Connection left, Connection right)
    Parameters
    Type Name Description
    Connection left

    The first connection.

    Connection right

    The second connection.

    Returns
    Type Description
    bool

    True if the connections are equal.

    operator !=(Connection, Connection)

    Checks whether two connections are different. See Equals(Connection).

    Declaration
    public static bool operator !=(Connection left, Connection right)
    Parameters
    Type Name Description
    Connection left

    The first connection.

    Connection right

    The second connection.

    Returns
    Type Description
    bool

    True if the connections are not equal.

    Implements

    IEquatable<T>
    In This Article
    Back to top
    Copyright © 2026 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)