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 Auto
Implements
Inherited Members
Namespace: Unity.NetCode
Assembly: solution.dll
Syntax
[Preserve]
public class ClientServerBootstrap : ICustomBootstrap
Remarks
We strongly recommend setting Application.runInBackground = true;
(or project-wide via Project Settings) once you intend to connect to the server (or accept connections on said server).
If you don't, your multiplayer will stall (and likely disconnect) if and when the application loses focus (e.g. by the player tabbing out), as netcode will be unable to tick (due to the application pausing).
In fact, a Dedicated Server Build should probably always have Run in Background
enabled.
We provide suppressible error warnings for this case via WarnAboutApplicationRunInBackground
.
Constructors
Name | Description |
---|---|
Client |
Initialize the bootstrap class and reset the static data everytime a new instance is created. |
Fields
Name | Description |
---|---|
Auto |
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 |
Default |
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 `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. |
Default |
The default address to listen on when using auto connect ( |
k_Max |
The maximum number of thin clients that can be created in the editor. Created to avoid self-inflicted long editor hangs, although removed as users should be able to test large player counts (e.g. for UTP reasons). |
Properties
Name | Description |
---|---|
Client |
A reference to the client world, assigned during the default client world creation. If there were multiple worlds created this will be the first one. |
Client |
A list of all client worlds created during the default creation flow. If this type of world is created manually and not via the bootstrap APIs this list needs to be manually populated. |
Has |
Check if a world with a Game |
Has |
Check if a world with a Game |
Requested |
The current play mode, used to configure drivers and worlds. |
Server |
A reference to the server world, assigned during the default server world creation. If there were multiple worlds created this will be the first one. |
Server |
A list of all server worlds created during the default creation flow. If this type of world is created manually and not via the bootstrap APIs this list needs to be manually populated. |
Thin |
A list of all thin client worlds created during the default creation flow. If this type of world is created manually and not via the bootstrap APIs this list needs to be manually populated. |
Will |
Check if the server should start listening for incoming connection automatically after the world has been created.
If the Auto |
Methods
Name | Description |
---|---|
Create |
Utility method for creating new clients worlds.
Can be used in custom implementations of |
Create |
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 |
Create |
Utility method for creating a local world without any NetCode systems. Name of the world instantiated. |
Create |
Utility method for creating a new server world.
Can be used in custom implementations of |
Create |
Utility method for creating thin clients worlds.
Can be used in custom implementations of |
Initialize(string) | Implement the ICustomBootstrap interface. Create the default client and server worlds
based on the Requested |