docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NetcodeWorld

    Provides various utility APIs for the current world. Most of these should have an ECS counter part, this class simply provides direct access to those various components. Provides shortcuts to its current Connection if online, its various singletons, etc.

    Inheritance
    object
    NetcodeWorld
    Namespace: Unity.Netcode
    Assembly: Unity.NetCode.dll
    Syntax
    public class NetcodeWorld : World

    Properties

    AllConnections

    All connections known to this world. Populated on the server, empty on clients.

    Declaration
    public List<Connection> AllConnections { get; }
    Property Value
    Type Description
    List<Connection>

    ClientServerTickRate

    The ClientServerTickRate singleton is used to configure the client and server simulation time step, server packet send rate and other related settings. The singleton entity is automatically created for the clients in the NetworkStreamReceiveSystem first update if not present. On the server, by contrast, the entity is never automatically created and it is up to the user to create the singletong instance if they need to. This behaviour is asymmetric because the client need to have this singleton data synced with the server one. It is like this for compatibility reason and It may be changed in the future. In order to configure these settings you can either:

    • Create the entity in a custom Unity.Netcode.ClientServerBootstrap after the worlds has been created.
    • On a system, in either the OnCreate or OnUpdate.
    It is not mandatory to set all the fields to a proper value when creating the singleton. It is sufficient to change only the relevant setting, and call the ResolveDefaults() method to configure the fields that does not have a value set. The ClientServerTickRate settings are synced as part of the of the initial client connection handshake. (ClientServerTickRateRefreshRequest data). The ClientServerTickRate should also be used to customise other server only timing settings, such as
    • the maximum number of tick per frame
    • the maximum number of tick per frame
    • tick batching (<`MaxSimulationStepBatchSize`) and others.
    See the individual fields documentation for more information.
    Declaration
    public ClientServerTickRate ClientServerTickRate { get; }
    Property Value
    Type Description
    ClientServerTickRate

    ClientTickRate

    Create a ClientTickRate singleton in the client world (either at runtime or by loading it from sub-scene) to configure all the network time synchronization, interpolation delay, prediction batching and other setting for the client. See the individual fields for more information about the individual properties.

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

    DeltaTime

    The delta time of the current world update in seconds, or 0 if the world is not initialized.

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

    LocalConnection

    Your local connection, for the current client. For a host, this is your "main" virtual local connection. The network ID and other values default to 0 when there is no connection.

    Declaration
    public Connection LocalConnection { get; }
    Property Value
    Type Description
    Connection

    NetworkTime

    The Unity.Netcode.NetworkTime singleton of this world, or a default value if the world is not initialized.

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

    PredictionSwitching

    Gives access to switching ghosts between predicted and interpolated modes. Only available on client worlds.

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

    Methods

    Connect(NetworkEndpoint)

    Connect the client to the specified server endpoint. You can override driver creation by setting DriverConstructor with your own constructor.

    Declaration
    public Connection Connect(NetworkEndpoint endpoint)
    Parameters
    Type Name Description
    NetworkEndpoint endpoint

    The NetworkEndpoint to connect to. Examples:

    NetworkEndpoint.LoopbackIpv4.WithPort(1234) // to connect to localhost
    NetworkEndpoint.Parse("1.2.3.4", 1234) // to parse a string
    Returns
    Type Description
    Connection

    True if successful, Shutdown will be called on client connection issues.

    DisconnectAClient(Connection)

    Requests the server to disconnect the client behind the given connection. Only valid on the server.

    Declaration
    public void DisconnectAClient(Connection connection)
    Parameters
    Type Name Description
    Connection connection

    The connection of the client to disconnect.

    DisconnectAClient(NetworkId)

    Requests the server to disconnect the client with the given network id. Only valid on the server.

    Declaration
    public void DisconnectAClient(NetworkId clientId)
    Parameters
    Type Name Description
    NetworkId clientId

    The NetworkId of the client to disconnect.

    Listen(NetworkEndpoint)

    Starts the server and listens on the given endpoint. You can override driver creation by setting DriverConstructor with your own constructor.

    Declaration
    public bool Listen(NetworkEndpoint endpoint)
    Parameters
    Type Name Description
    NetworkEndpoint endpoint

    The NetworkEndpoint to listen on. To listen for any address for example, use

    NetworkEndpoint.AnyIpv4.WithPort(123)
    Returns
    Type Description
    bool

    True if successful, Shutdown will be called on issues.

    Listening()

    Check if the server world is set up and valid and has a driver instance listening.

    Declaration
    public bool Listening()
    Returns
    Type Description
    bool

    True if server is listening.

    RequestDisconnectAllClients()

    Requests the server to disconnect all connected clients. Only valid on the server.

    Declaration
    public void RequestDisconnectAllClients()

    RequestDisconnectFromServer()

    Requests the local client connection to disconnect from the server. Only valid on client worlds.

    Declaration
    public void RequestDisconnectFromServer()

    Shutdown()

    Flushes all pending messages on connections and requests a disconnect on those connections. This will be processed in the next frame and so your connections will still be marked as connected after this call.

    Declaration
    public void Shutdown()

    Events

    OnConnectionEvent

    Event called for any connection event, both client side or server side. A State is available to differentiate the different events. This is called from ECS's SimulationSystemGroup's beginning and so should execute right after MonoBehaviour.Update(). See ConnectionManagementUpdateConnections. This will also get called on world destruction when shutting down.

    Declaration
    public event OnConnectionEventDelegate OnConnectionEvent
    Event Type
    Type Description
    OnConnectionEventDelegate
    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)