OnSerializeNetworkView doesn’t seem to be working properly. It works fine in 4.6 but not in 5 beta. The BitStream that it supplies is null. I couldn’t report it as a bug because the reporter kept failing.
Example code:
Make a GameObject then put a NetworkView on it that is set to observe this component which should also be on the object. Make a standalone build and run both it and the editor. You will see errors about the BitStream being null. If you do the same process but in Unity 4.6, it won’t be null.
using UnityEngine;
//Running this in the Unity Editor will result in initializing the server
//Running it as a Standalone build will result in connecting as client
//The server will bring up errors in the console letting you know that the BitStream is null for OnSerializeNetworkView
public class Connect : MonoBehaviour {
bool tryToConnect = true;
void Start() {
if(Application.isEditor)
Network.InitializeServer(16, 9001, true);
}
void Update() {
if(!Application.isEditor) {
if(tryToConnect)
if(!Network.isClient && Network.peerType != NetworkPeerType.Connecting) {
Network.Connect("127.0.0.1", 9001);
tryToConnect = false;
}
}
}
void OnFailedToConnect() {
tryToConnect = true;
}
void OnDisconnectedFromServer() {
tryToConnect = true;
}
void OnSerializeNetworkView(BitStream stream) {
if(stream == null)
Debug.LogError("BitStream is null");
}
void OnGUI() {
if(Network.isServer)
GUILayout.Label("Server Online");
else if(Network.isClient)
GUILayout.Label("Client Online");
else
GUILayout.Label("Connecting");
}
}