Class AutomaticThinClientWorldsUtility
Have netcode automatically manage thin clients for you by assigning Num
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
public class AutomaticThinClientWorldsUtility
Fields
BootstrapInitialization
If your automatic thin clients need custom initialization during bootstrap (e.g. due to custom scene management settings),
modify this delegate. Uses Default
Declaration
public static AutomaticThinClientWorldsUtility.ThinClientWorldInitializationDelegate BootstrapInitialization
Field Value
Type | Description |
---|---|
Automatic |
CreationFrequency
The frequency with which we should create the thin client worlds (in hertz i.e. worlds per second).
0 denotes 'create all immediately'.
If null (the default), it'll use Thin
Declaration
public static float? CreationFrequency
Field Value
Type | Description |
---|---|
float? |
NumThinClientsRequested
Set the desired number of thin client worlds.
Declaration
public static int? NumThinClientsRequested
Field Value
Type | Description |
---|---|
int? |
Remarks
If null (the default), it'll use Requested
ReferenceWorld
The world to use for data injection (like to know which sub-scene(s) to load).
If null, we'll try to use any existing client or server worlds, found via Client
Declaration
public static World ReferenceWorld
Field Value
Type | Description |
---|---|
World |
RuntimeInitialization
If your automatic thin clients need custom initialization at runtime (e.g. due to custom scene management settings),
modify this delegate. Uses Default
Declaration
public static AutomaticThinClientWorldsUtility.ThinClientWorldInitializationDelegate RuntimeInitialization
Field Value
Type | Description |
---|---|
Automatic |
Properties
AutomaticallyManagedWorlds
A list of all thin client worlds created by (and managed by) the netcode package itself. If you add a thin client to this list, netcode will take ownership of it. This list prevents the netcode package from deleting your thin client worlds.
Declaration
public static List<World> AutomaticallyManagedWorlds { get; }
Property Value
IsBootstrapInitializationEnabled
Denotes if automatic bootstrap thin client creation is enabled.
Declaration
public static bool IsBootstrapInitializationEnabled { get; }
Property Value
Type | Description |
---|---|
bool |
IsRuntimeInitializationEnabled
Denotes if automatic RUNTIME thin client creation is enabled.
Declaration
public static bool IsRuntimeInitializationEnabled { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
BootstrapThinClientWorlds()
Use this method when inside the Initialize(string) flow.
Declaration
public static void BootstrapThinClientWorlds()
Remarks
This has to exist because Entities/Netcode uses a fast-path, where it loads the entity scene data (for all loaded scenes) once, and then auto-injects said data into all appropriate bootstrapping worlds.
CleanupWorlds()
Utility to remove all stale worlds from the list.
Declaration
public static int CleanupWorlds()
Returns
Type | Description |
---|---|
int | Num removed. |
DefaultBootstrapThinClientWorldInitialization(World)
By default, thin clients created during the bootstrap will automatically be injected with the loaded scenes sub-scenes. Thus, we do not need to do anything custom.
Declaration
public static World DefaultBootstrapThinClientWorldInitialization(World referenceWorld)
Parameters
Type | Name | Description |
---|---|---|
World | referenceWorld | The world to reference when creating this one (for the purposes of scene loading etc.). |
Returns
Type | Description |
---|---|
World | The newly created world, otherwise null. |
DefaultRuntimeThinClientWorldInitialization(World)
If your automatic thin clients need custom initialization at runtime (e.g. due to custom scene management settings),
modify this delegate. Uses Default
Declaration
public static World DefaultRuntimeThinClientWorldInitialization(World referenceWorld)
Parameters
Type | Name | Description |
---|---|---|
World | referenceWorld | The world to reference when creating this one (for the purposes of scene loading etc.). |
Returns
Type | Description |
---|---|
World | The newly created world, otherwise null. |
UpdateAutomaticThinClientWorlds()
If you use this feature, call this method in a Mono
Declaration
public static bool UpdateAutomaticThinClientWorlds()
Returns
Type | Description |
---|---|
bool | True if any worlds were created or destroyed. |
UpdateAutomaticThinClientWorldsImmediate(World, int, int, out bool)
Creates and/or Disposes thin client worlds until the final count is equal to targetThinClientCount.
Declaration
public static NativeList<WorldUnmanaged> UpdateAutomaticThinClientWorldsImmediate(World referenceWorld, int targetThinClientCount, int maxAllowedSpawn, out bool didCreateOrDestroy)
Parameters
Type | Name | Description |
---|---|---|
World | referenceWorld | The desired world to use as a reference. If null, we'll try to use any existing client or server worlds. |
int | targetThinClientCount | The desired final count of thin clients. |
int | maxAllowedSpawn | Rate limiting feature. Worlds are disposed immediately, but only instantiated at this frequency. |
bool | didCreateOrDestroy | True if worlds were created or destroyed. |
Returns
Type | Description |
---|---|
Native |
The list of successfully created worlds, otherwise default. |