Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Initializing a SyncVar during OnServerAddPlayer causes Error

Discussion in 'Multiplayer' started by bsterling250DI, Jun 22, 2015.

  1. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    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.
     
    Last edited: Jun 22, 2015
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    there was a bug in networktransform that could cause this. try upgrading to latest patch release.
     
  3. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    sorry, i'm on 5.1.1f1 and there are no patch releases for 5.1.1 yet
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    can you post a simple repro case? this should work.
     
  5. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    putting one together now.
     
  6. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    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.
     
  7. MarxentAnthony

    MarxentAnthony

    Joined:
    Feb 20, 2015
    Posts:
    18
    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.
     
  8. peterept2

    peterept2

    Joined:
    Aug 1, 2012
    Posts:
    41
    Unfortunately NetworkTransform's on child game objects dont get sync'd.