docs.unity3d.com
    Show / Hide Table of Contents

    Class ClientServerBootstrap

    ClientServerBootstrap is responsible to configure and create the Server and Client worlds at runtime when the game start (in the editor when entering PlayMode). The ClientServerBootstrap is meant to be a base class for your own custom boostrap code and provides utility methods that make it easy creating the client and server worlds. It also support connecting the client to server automatically, using the AutoConnectPort port and DefaultConnectAddress. For the server, it allow binding the server transport to a specific listening port and address (especially useful when running the server on some cloud provider) via DefaultListenAddress.

    Inheritance
    Object
    ClientServerBootstrap
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.NetCode
    Syntax
    [Preserve]
    public class ClientServerBootstrap : ICustomBootstrap

    Constructors

    ClientServerBootstrap()

    Initialize the bootstrap class and reset the static data everytime a new instance is created.

    Declaration
    public ClientServerBootstrap()

    Fields

    AutoConnectPort

    The default port to use for auto connection. The default value is zero, which means do not auto connect. If this is set to a valid port any call to CreateClientWorld - including CreateDefaultWorlds and Initialize - will try to connect to the specified port and address - assuming DefaultConnectAddress is valid. Any call to CreateServerWorld - including CreateDefaultWorlds and Initialize - will listen on the specified port and listen address.

    Declaration
    public static ushort AutoConnectPort
    Field Value
    Type Description
    UInt16

    DefaultConnectAddress

    The default address to connect to when using auto connect (AutoConnectPort is not zero). If this value is NetworkEndPoint.AnyIpv4 auto connect will not be used, even if the port is specified. This is to allow auto listen without auto connect.

    The address specified in the Multiplayer PlayMode Tools window takes precedence over this when running in the editor (in PlayType.Client). If that address is not valid or you are running in a player, then DefaultConnectAddress will be used instead.

    Declaration
    public static NetworkEndpoint DefaultConnectAddress
    Field Value
    Type Description
    NetworkEndpoint
    Remarks

    Note that the DefaultConnectAddress.Port will be clobbered by the AutoConnectPort if it's set.

    DefaultListenAddress

    The default address to listen on when using auto connect (AutoConnectPort is not zero).

    Declaration
    public static NetworkEndpoint DefaultListenAddress
    Field Value
    Type Description
    NetworkEndpoint

    k_MaxNumThinClients

    The maximum number of thin clients that can be created in the editor.

    Declaration
    public const int k_MaxNumThinClients = 32
    Field Value
    Type Description
    Int32

    Properties

    HasClientWorlds

    Check if a world with a GameClient is present. If at least one world with GameClient flags has been created.

    Declaration
    public static bool HasClientWorlds { get; }
    Property Value
    Type Description
    Boolean

    HasServerWorld

    Check if a world with a GameServer is present. If at least one world with GameServer flags has been created.

    Declaration
    public static bool HasServerWorld { get; }
    Property Value
    Type Description
    Boolean

    RequestedPlayType

    The current play mode, used to configure drivers and worlds.

    Declaration
    public static ClientServerBootstrap.PlayType RequestedPlayType { get; }
    Property Value
    Type Description
    ClientServerBootstrap.PlayType

    WillServerAutoListen

    Check if the server should start listening for incoming connection automatically after the world has been created.

    If the AutoConnectPort is set, the server should start listening for connection using the DefaultConnectAddress and AutoConnectPort.

    Declaration
    public static bool WillServerAutoListen { get; }
    Property Value
    Type Description
    Boolean

    Methods

    CreateClientWorld(String)

    Utility method for creating new clients worlds. Can be used in custom implementations of Initialize as well at runtime, to add new clients dynamically.

    Declaration
    public static World CreateClientWorld(string name)
    Parameters
    Type Name Description
    String name

    The client world name

    Returns
    Type Description
    World

    CreateDefaultClientServerWorlds()

    Utility method for creating the default client and server worlds based on the settings in the playmode tools in the editor or client / server defined in a player. Should be used in custom implementations of Initialize.

    Declaration
    protected virtual void CreateDefaultClientServerWorlds()

    CreateLocalWorld(String)

    Utility method for creating a local world without any NetCode systems. Name of the world instantiated. World with default systems added, set to run as the Main Live world. See WorldFlags.Game

    Declaration
    public static World CreateLocalWorld(string defaultWorldName)
    Parameters
    Type Name Description
    String defaultWorldName

    The name to use for the default world.

    Returns
    Type Description
    World

    A new world instance.

    CreateServerWorld(String)

    Utility method for creating a new server world. Can be used in custom implementations of Initialize as well as in your game logic (in particular client/server build) when you need to create server programmatically (ex: frontend that allow selecting the role or other logic).

    Declaration
    public static World CreateServerWorld(string name)
    Parameters
    Type Name Description
    String name

    The server world name

    Returns
    Type Description
    World

    CreateThinClientWorld()

    Utility method for creating thin clients worlds. Can be used in custom implementations of Initialize as well at runtime, to add new clients dynamically.

    Declaration
    public static World CreateThinClientWorld()
    Returns
    Type Description
    World

    Initialize(String)

    Implement the ICustomBootstrap interface. Create the default client and serer worlds by based on the RequestedPlayType. In the editor, it also create thin clients worlds, if is not 0. As part of the initialization process, if the

    Declaration
    public virtual bool Initialize(string defaultWorldName)
    Parameters
    Type Name Description
    String defaultWorldName

    The name to use for the default world. Unused, can be null or empty

    Returns
    Type Description
    Boolean
    Implements
    ICustomBootstrap.Initialize(String)
    In This Article
    • Constructors
      • ClientServerBootstrap()
    • Fields
      • AutoConnectPort
      • DefaultConnectAddress
      • DefaultListenAddress
      • k_MaxNumThinClients
    • Properties
      • HasClientWorlds
      • HasServerWorld
      • RequestedPlayType
      • WillServerAutoListen
    • Methods
      • CreateClientWorld(String)
      • CreateDefaultClientServerWorlds()
      • CreateLocalWorld(String)
      • CreateServerWorld(String)
      • CreateThinClientWorld()
      • Initialize(String)
    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