Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity 5.0.0b18 - OnSerializeNetworkView Bug

Discussion in 'Unity 5 Pre-order Beta' started by GibTreaty, Dec 26, 2014.

  1. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    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.

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. //Running this in the Unity Editor will result in initializing the server
    4. //Running it as a Standalone build will result in connecting as client
    5. //The server will bring up errors in the console letting you know that the BitStream is null for OnSerializeNetworkView
    6. public class Connect : MonoBehaviour {
    7.  
    8.    bool tryToConnect = true;
    9.  
    10.    void Start() {
    11.      if(Application.isEditor)
    12.        Network.InitializeServer(16, 9001, true);
    13.    }
    14.  
    15.    void Update() {
    16.      if(!Application.isEditor) {
    17.        if(tryToConnect)
    18.          if(!Network.isClient && Network.peerType != NetworkPeerType.Connecting) {
    19.            Network.Connect("127.0.0.1", 9001);
    20.            tryToConnect = false;
    21.          }
    22.      }
    23.    }
    24.  
    25.    void OnFailedToConnect() {
    26.      tryToConnect = true;
    27.    }
    28.  
    29.    void OnDisconnectedFromServer() {
    30.      tryToConnect = true;
    31.    }
    32.  
    33.    void OnSerializeNetworkView(BitStream stream) {
    34.      if(stream == null)
    35.        Debug.LogError("BitStream is null");
    36.    }
    37.  
    38.    void OnGUI() {
    39.      if(Network.isServer)
    40.        GUILayout.Label("Server Online");
    41.      else if(Network.isClient)
    42.        GUILayout.Label("Client Online");
    43.      else
    44.        GUILayout.Label("Connecting");
    45.    }
    46. }
     
    Infos2, BenCP and MrEsquire like this.
  2. Infos2

    Infos2

    Joined:
    Jan 18, 2015
    Posts:
    6
    Sorry for my english.

    I have similar situation. Bug in OnSerializeNetworkView exists 100%. I got my working project from unity 4.5.5 and in unity 5 it doesn't work. If i use even clear method "void OnSerializeNetworkView(...) { } ", unity tells that i have error like null reference. When i delete "void OnSerializeNetworkView(...) { } " from my code, errors disappear. Fix it pls.
     
  3. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Fear no more, I had sent in a bug report and it looks like it'll be fixed (don't know when).
    663681
     
  4. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    Thanks for finding and reporting this bug @GibTreaty. It still exists in RC2 and I came across it with a slight variation: If you add the NetworkMessageInfo parameter to your OnSerializeNetworkView method then the method never actually gets called and instead you get a NullReferenceException in the console/log with no stacktrace whatsoever.
     
    Last edited: Feb 19, 2015
    GibTreaty likes this.
  5. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    I'm experiencing the same issue.
     
  6. LastLance

    LastLance

    Joined:
    Feb 22, 2015
    Posts:
    52
    Same here. In rc1, rc2 - same bug. Lose 2 days on finding and fixing result = null. In 4.6 all works by 100%.
     
  7. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    I didn't see it mentioned in the release notes, but this appears to be fixed in RC3. Thank you to whoever fixed it! :)
     
    GibTreaty likes this.
  8. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    Yep, it's fixed!
     
  9. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    Cool i'll be updating to RC3 then!
     
    GibTreaty likes this.