
The callback function OnStartServer is invoked for all networked objects when the client becomes a new host. So any data on the host that is not stored in SyncVars or SyncLists will not be available after a host migration. If there is data that is only on the server, then it will not be available to the client that becomes the new host. NOTE: Only data that is available to clients will be preserved during a host migration. So no player state data is lost during a host migration. Then, when the other clients rejoin the new game on the new host, the corresponding players for those clients are re-enabled on the host, and respawned on the other clients.

This also applies to custom serialized data for objects.Īll of the player objects in the game are disabled when the host is lost. The state of SyncVars and SyncLists on all networked objects in the scene are maintained during a host migration. The Network Migration Manager prototyping HUDĮven though the migration may have occurred because the old host lost connection or quite the game, it is possible for the old host of the game to rejoin the game as a client on the new host. This user interface is intended for testing and prototyping a real game would implement a custom user interface for host migration, and probably custom logic - possibly choosing the new host automatically without requiring input from the user. There is a simple user interface provided by the NetworkMigrationManager, similar to the NetworkManagerHUD. Below is a screenshot of the NetworkMigrationManager in the editor inspector. The new NetworkMigrationManager component can be dropped into a multiplayer game that uses the Unity Networking HLAPI, and it allows the game to continue with a new host after the original host is lost. The other peers then connect to the new host and the game can continue. When the host is lost, one peer can become the new host. How it worksĭuring a multiplayer game with host migration enabled, the addresses of the peers will be distributed to the peers in the game.

The “Host Migration” feature allows one of the remote clients to become the new host, so that the multiplayer game can continue. The host could be lost because the player left, the host process was killed or crashed, the host’s machine was shut down, or because the network connection of the host was lost. If the host of a game is lost, then the game cannot continue. It runs a server and a “local client”, while the other peers each run a “remote client”. So, my question is, can I get Unity's NetworkView.RPC method to put it's serialised objects into this "args" parameter? If not, can anyone see anyway around this?īy the way I'm using Vexe's framework, so you might see unusual things like "base.Serializer" etc.In a multiplayer network game without a dedicated server, one of the peers in the game acts as the center of authority for the game. Object deserialisedArgs = new object įor( int i = 0 i ( ( string )args ) First we have to deserialise the method arguments. The RPC method: private void ComponentRPCNetwork( params object args ) The only problem now is, Unity won't put the objects it serialises into my params object parameter.

I also put the unique component name and method name in the array. NetworkView.RPC( "ComponentRPCNetwork", mode, serialisedObjects )

Serialise arguments and call our RPC method through Unity. So, I now I serialise them IF they're not a NetworkViewID, then send the entire object array to Unity, which it does interpret correctly: protected void ComponentRPC( string methodName, RPCMode mode, params object args ) So, serialising the whole array of objects isn't an option.
Unity transfer networkview to new server how to#
That's fine, except as far as I can tell, Unity's NetworkView.RPC method is the only thing in the universe that knows how to serialise a NetworkViewID properly. Serialising the entire array results in Unity doing no serialisation in NetworkView.RPC. This method simply serialises the parameters into a string and sends them to unity's RPC method. So, now every RPC call should go through my RPC method. So, to fix this I've added a unique name to every component and have to do some relatively slow searching and reflection in order to have a safe RPC call. This means an arbitrary component will be the "this" of the RPC method that actually gets called. "RPC function names should be unique accross the scene, if two RPC functions in different scripts have the same name only one of them is called when RPC is invoked" This means if I have two components that share a base class that has an RPC method, they won't work due to this: Every component that a game object uses is placed on the object and is disabled/enabled based on it's state machine's current state. Why do I need to do this? The game I'm working on fully conforms to a component style design.
