Migrate to uLink
It is easy to migrate from Unity's built-in networking to uLink networking. Install uLink, start the converter from the uLink menu in the editor and convert the complete game in two steps.
If you want to read what the converter does or want to learn how to do the migration manually read the rest of this chapter.
Game object and prefab changes
- Do not use the Unity
NetworkViewcomponent in your prefabs or game objects. Use the
uLinkNetworkViewscript component instead.
- If the game object is listed in the hierarchy view in the Unity editor, a
Manual View IDhas to be given to the
uLinkNetworkViewcomponent. When the component is added, choose a number starting from 1. Assign a unique number to every game object. Game objects that are instantiated dynamically with
uLink.Network.Instantiate()will get a unique
viewIDautomatically during runtime.
- All prefabs that will be used in
uLink.Network.Instantiate()must be placed in the folder Assets/Resources. Do not place these prefabs in subfolders. There is no limitation to the file location for prefabs when using
- Not mandatory, but recommended: All prefabs that will be used in
uLink.Network.Instantiate()should not have multiple
uLinkNetworkViewcomponents. Instead there is a special script called
uLinkObservedListthat should be used. Use this list as a container for all other components that needs to be synchronized over the network. For example, if you want to sync both the transform and the animation of an avatar, this is the way to go. The prefab that is instantiated using
uLink.Network.Instantiate()should have one
uLinkObservedListof length two, containing two components; the transform and the animation script. More details about this is covered in the Network Views chapter. The uLink converter does not do this change, you have to do this refactoring manually.
General code changes
- Add the
uLinknamespace to all network related classes, enums and structs. Two examples: Change from
uLink.NetworkPlayerand change from
- Add the
uLink_prefix to all network related messages (events) like this:
uLink_OnServerConnected(). For a complete list of all network related messages available in
uLink, look at Appendix A.
- The usage of the keyword
networkViewshould be replaced with
uLink.NetworkView.Get(this)in all scripts. There are other way to replace it, documented in the end of the Network Views chapter, but we recommend this particular replacement because it works in all script languages and thus makes the migration work easier.
Special code changes
- If any script classes inherits private RPC methods from another script, then those RPC methods in their base class must made either public or protected, otherwise
uLinkwon't find them.
- Unity Network can only send RPCs within the same MonoBehaviour.
uLinkdoesn't have such a limitation, but as a result it wont allow multiple MonoBehaviours with the same RPC per NetworkView. If, for example, a NetworkView has two MonoBehaviours as RPC receivers and both have defined an RPC method named Jump, make sure that one of them changes the name of their RPC, otherwise it will be ambiguous. There is a new feature in
uLink 1.1that lets you restrict the sending of an RPC to just one type of Monobehaviour.
- If there are code setting the
viewIDproperty of any
NetworkViewdirectly, please replace it with a call to the method
NetworkView.SetManualViewID(). Otherwise the owner role will be
- If there are code using
NetworkPeerType.Connectingthis has to be replaced because that type has been removed.
uLinkseparates peer types and connection statuses in a more clean way. Take a look at the two properties
- The message
uLink_OnDisconnectedFromServer()will not be fired on the server when using
uLink. If there are code using this message on the server side for handling situations when the server is disconnecting make sure the code instead uses the new uLink message
- The behaviour of
uLink.Network.isClientis slightly different. uLink returns
truewhen the client in connecting state and connected state, Unity returns true only when connected. It is possible to get the exact same behaviour in uLink with this code snippet:
(uLink.Network.isClient && uLink.Network.status == uLink.NetworkStatus.Connected)