Initializing a SyncVar during OnServerAddPlayer causes Error

Hi,

I am working on an RTS style game, and i have a simple network behaviour that has one single syncvar of an int for a TeamID.

Inside OnServerAddPlayer i instantiate my player prefab which has this component and set the value before calling NetworkServer.AddPlayerForConnection.

If i comment out the line that sets the value i get no errors.

with it uncommented i get the following when a client connects to the server.

IndexOutOfRangeException: NetworkReader:ReadByte out of range:NetBuf sz:13 pos:13
UnityEngine.Networking.NetBuffer.ReadByte () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkBuffer.cs:35)
UnityEngine.Networking.NetworkReader.ReadUInt32 () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkReader.cs:200)
UnityEngine.Networking.NetworkReader.ReadSingle () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkReader.cs:273)
UnityEngine.Networking.NetworkReader.ReadVector3 () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkReader.cs:346)
UnityEngine.Networking.NetworkTransform.UnserializeModeTransform (UnityEngine.Networking.NetworkReader reader, Boolean initialState) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkTransform.cs:399)
UnityEngine.Networking.NetworkTransform.OnDeserialize (UnityEngine.Networking.NetworkReader reader, Boolean initialState) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkTransform.cs:368)
UnityEngine.Networking.NetworkIdentity.OnUpdateVars (UnityEngine.Networking.NetworkReader reader, Boolean initialState) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:534)
UnityEngine.Networking.ClientScene.OnUpdateVarsMessage (UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:591)
UnityEngine.Networking.NetworkConnection.HandleMessage (System.Collections.Generic.Dictionary`2 handler, UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:301)
UnityEngine.Networking.NetworkClient.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:472)
UnityEngine.Networking.NetworkClient.UpdateClients () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:686)
UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:707)

If i have a client that is also a Host this error happens, but doesn’t seem to have any visible issues to the user, but when connecting to a standalone server, and two separate clients, the clients don’t see the players transforms updating, and my game requires a persistent server.

edit: if i comment out this code, both player transforms update properly when connecting to a standalone server.

there was a bug in networktransform that could cause this. try upgrading to latest patch release.

sorry, i’m on 5.1.1f1 and there are no patch releases for 5.1.1 yet

can you post a simple repro case? this should work.

putting one together now.

strange, i closed down unity, and then created a new empty project to try and repro it, i couldnt repro it, and so i went back to my original project and its no longer occurring.

so, its mysteriously working now.

I get a similar bug when communicating across different platforms.

For Instance :

If I have a network build running between a Mac host and Mac client or a iOS host and iMac Client ( or any combination therein) and I move the player everything is fine.

However if I have a Mac Host communicating with a Windows Client I get IndexOutOfRangeException: NetworkReader:ReadByte out of range:NetBuf sz:27 pos:27 spamming the Windows Client console when it is moving. Note, it does not crash just a lot of spam.

Side note I also noticed that if said Windows client is an Oculus rift, the camera’s transforms are not transmitted even thought they are on an object with a Network Identity and network transform components. The camera is a grandchild to the player prefab.

Unfortunately NetworkTransform’s on child game objects dont get sync’d.