Class HostMigration
Host migration class used to access the host migration system, like getting the host migration data blob and functions for reacting to host migration events.
Inherited Members
Namespace: Unity.NetCode
Assembly: Unity.NetCode.dll
Syntax
public static class HostMigration
Methods
ConfigureClientAndConnect(World, INetworkStreamDriverConstructor, NetworkEndpoint)
Configure the client driver with the given driver constructor and connect to the endpoint. The NetworkDriverStore will be recreated as the client can be switching from a local IPC connection to relay connection or reversed, the relay data can be set at driver creation time.
Declaration
public static bool ConfigureClientAndConnect(World clientWorld, INetworkStreamDriverConstructor driverConstructor, NetworkEndpoint serverEndpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| World | clientWorld | The client world which needs to be configured. |
| INetworkStreamDriverConstructor | driverConstructor | The network driver constructor used for creating a new network driver in the client world. |
| NetworkEndpoint | serverEndpoint | The network endpoint the client will connect to after configuring the network driver. |
Returns
| Type | Description |
|---|---|
| bool | Returns true if the connect call succeeds |
GetHostMigrationData(World, ref NativeList<byte>)
Get the host migration data which has been collected by the host migration system. There is no limit enforced on the total size of the migration data.
Declaration
public static void GetHostMigrationData(World world, ref NativeList<byte> data)
Parameters
| Type | Name | Description |
|---|---|---|
| World | world | The world where the migration data is stored |
| NativeList<byte> | data | Destination list to copy the data, this will be resized if it is too small to store all the data |
MigrateDataToNewServerWorld(INetworkStreamDriverConstructor, ref NativeArray<byte>)
Optional helper method to assist with the operations needed during a host migration process. SetHostMigrationData(World, ref NativeArray<byte>) can also be called directly with a server world which has been manually set up to resume hosting with a given host migration data.
Takes the given host migration data and starts the host migration process. This starts loading the entity scenes the host previously had loaded (if any). The NetworkDriverStore and Unity.Networking.Transport.NetworkDriver in the new server world will be created appropriately, the driver constructor will need to be capable of setting up the relay connection with the given constructor. The local client world will switch from relay to local IPC connection to the server world.
Declaration
public static bool MigrateDataToNewServerWorld(INetworkStreamDriverConstructor driverConstructor, ref NativeArray<byte> migrationData)
Parameters
| Type | Name | Description |
|---|---|---|
| INetworkStreamDriverConstructor | driverConstructor | The network driver constructor registered in the new server world and also in the client world. |
| NativeArray<byte> | migrationData | The data blob containing host migration data, deployed to the new server world. |
Returns
| Type | Description |
|---|---|
| bool | Returns false if there was any immediate failure when starting up the new server |
SetHostMigrationData(World, ref NativeArray<byte>)
Deploy the given host migration data in the given world. The data needs to be collected by GetHostMigrationData(World, ref NativeList<byte>) and contains all the ghost data and specific host configuration data needed to set up the netcode state.
Declaration
public static void SetHostMigrationData(World world, ref NativeArray<byte> migrationData)
Parameters
| Type | Name | Description |
|---|---|---|
| World | world | Destination world to deploy the migration data |
| NativeArray<byte> | migrationData | Host migration data collected by the host migration system |
TryGetHostMigrationData(World, ref NativeArray<byte>, out int)
Get the host migration data which has been collected by the host migration system. There is no limit enforced on the total size of the migration data.
Declaration
public static bool TryGetHostMigrationData(World world, ref NativeArray<byte> data, out int size)
Parameters
| Type | Name | Description |
|---|---|---|
| World | world | The world where the migration data is stored |
| NativeArray<byte> | data | Destination buffer to copy the data into |
| int | size | The required size of the host data, this can be used to resize the destination buffer if it is too small |
Returns
| Type | Description |
|---|---|
| bool | True if the data was successfully copied |