I’m attempting to upgrade my project from 5.1.1f1 to 5.2.0p1 (Windows). I am running into a serialization mismatch on the (non-host) clients, where they read the wrong number of bytes from their NetworkReaders. I am building my server and clients with matching versions of Unity. Any API changes that could lead to this? I noticed NetworkClient.isConnected for the first time during this process, as the client was attempting to send when NetworkClient.active was true, and I received a new error in this case, which I prevent by checking NetworkClient.isConnected.
Did the behavior of NetworkClient.active, such as whether it returns true when connected or not, change in 5.2?
NetworkClient.active is static (global), and is true if any NetworkClient instance exists. Primary useful to check if you are running on a server or a client.
client.isConnected is an instance member variable (not global) that is true if that particular client is connected to a server.
I still haven’t tracked down the issue. The serialization mismatch doesn’t happen on a host sending to its own client, but only on our server to separate client. I get a lot of errors on the client where (I think) the deserialization tries to read too much, like this
Everything is pointing to our custom serialization functions. Here is how our OnDeserialize methods tend to look, ever since the change where they can be called with zero dirty bits:
public override void OnDeserialize(NetworkReader reader, bool initialState)
{
uint syncVarDirtyBits = 0xFFFFFFFF; // TODO rename, now that the NetworkBehaviour property shares this name
if (!initialState)
{
syncVarDirtyBits = reader.ReadPackedUInt32();
}
if (syncVarDirtyBits != 0)
{
// read the network reader for the bits dirty
}
}
What is a NetworkBehaviour script script interface?
Do you mean things that derive from NetworkBehaviour indirectly? Like
class Foo : NetworkBehaviour { ... }
class Bar : Foo { ... }
So, are you suggesting I need this:
class Foo : NetworkBehaviour {
... OnDeserialze(...) { ...}
}
class Bar : Foo {
... OnDeserialize(...) {
base.OnDeserialize(...);
....
}
}
The only case we have like that is where Foo (parent class) has sealed overrides for OnSerialize and OnDeserialize, and the child classes do not use SyncVar or SyncList, they just override a helper function.
The buffers in the NetworkReaders recieved by the client in OnDeserialize are smaller than the ones written to by the server, using the same build. The server finishes a message, writing to position 23 in a buffer with a 4 byte “header” (written to by the HLAPI/EndMessage?). The client receives a buffer with only 20 bytes, including a 6 byte header. This only occurs in 5.2, not 5.1.
Are you using the built-in network simulator? There were issues like that reported before and using some external simulatio instead made the problem go away.