Search Unity

Network Spawn/Sync issues

Discussion in 'Multiplayer' started by spaceman8, Mar 28, 2017.

  1. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    I'm expanding my game to use the network match making service and relay servers, I am at the point where the server and clients can now join a game and players are created, etc.. however on the client I am seeing these messages in the log:

    Spawn scene object not found for X
    Did not find target for sync message for X


    I suspect the 2nd one is a result of the first but I am not sure yet. Looking at the ClientScene code I see the first message happens when a network identity is null as a result of looking up an object using its sceneId. I started digging then to see what my object sceneId's are and most are 0 but then a few are not. Should these all be the same for a given scene? If so how do I go about resetting? What would cause these to get out of sync between the server and client?

    Update: it looks like my scene id's are only 0 when I am in edit mode, in play mode they all get assigned a unique id.

    Thanks.
     
    Last edited: Mar 28, 2017
  2. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    I'm not sure if this is related but when I host in the standalone project it looks like objects are trying to be spawned that shouldn't be, this message for example:

    Sending spawn message for current server objects name='OrbSentry' netId=1

    This is my menu scene and I do not have any instances of my OrbSentry in the scene nor am I spawning anything through code. Then I notice from another one of my posts I start getting this message:
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3.   at UnityEngine.Networking.NetworkTransform.SerializeMode3D (UnityEngine.Networking.NetworkWriter writer) [0x00069] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkTransform.cs:256
    4.   at UnityEngine.Networking.NetworkTransform.OnSerialize (UnityEngine.Networking.NetworkWriter writer, Boolean initialState) [0x0006f] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkTransform.cs:200
    5.  
    And this scene has zero objects with NetworkTransforms. This is very frustrating and odd.
     
  3. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    I did another test, this is on my main menu with only a single network object I use for debugging, after I create a match and call StartHost() I query the ClientScene.objects dictionary and this is 3 total objects, my debug object (good) and then 2 of my creature objects that are not used in this scene anywhere.. Why are they showing up there? It feels like the underlying data being used by the server is corrupt, is there a way to rebuild this? Otherwise I have no idea what is going on.
     
  4. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    Digging deeper... I am now debugging the unet source directly. A few things I've learned:

    1> the objects getting spawned are _any_ resource that happens to contain a NetworkIdentity. I assume this is for some internal book keeping.

    Update: this is incorrect, only some of them are being loaded.. not sure why these 3 were selected out of the pool of them. ????

    2> the NullReferenceException I am seeing is being caused by one of those objects getting spawned but its Awake is never called therefor the NetworkTransform's m_RigidBody3D property is null which is not being checked as its being serialized.

    Adding a null check for m_RigidBody3D at the top of SerializeMode3D gets rid of this error but not sure what side effects this might be introducing..

    Does anyone know a way to copy the unet dll's into the project/unity that does not require me to close the project and delete my Library directory each time I want to update them?
     
    Last edited: Mar 29, 2017
  5. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    This is lovely, now when running the client in standalone mode and the server in the editor I get this on the client once I start a scene:

    Code (csharp):
    1.  
    2. InvalidOperationException: out of sync
    3.   at System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Int32].VerifyState () [0x00028] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:912
    4.   at System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Int32].MoveNext () [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:835
    5.   at System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator[System.String,System.Int32].MoveNext () [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:1028
    6.   at UnityEngine.Networking.NetworkCRC.Dump (UnityEngine.Networking.NetworkSystem.CRCMessageEntry[] remoteScripts) [0x00058] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkCRC.cs:109
    7.   at UnityEngine.Networking.NetworkCRC.ValidateInternal (UnityEngine.Networking.NetworkSystem.CRCMessageEntry[] remoteScripts, Int32 numChannels) [0x0002f] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkCRC.cs:77
    8.   at UnityEngine.Networking.NetworkCRC.Validate (UnityEngine.Networking.NetworkSystem.CRCMessageEntry[] scripts, Int32 numChannels) [0x00001] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkCRC.cs:68
    9.   at UnityEngine.Networking.NetworkClient.OnCRC (UnityEngine.Networking.NetworkMessage netMsg) [0x0000d] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkClient.cs:889
    10.   at UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) [0x00132] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkConnection.cs:467
    11.   at UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) [0x00008] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkConnection.cs:424
    12.   at UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) [0x00001] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkConnection.cs:574
    13.   at UnityEngine.Networking.NetworkClient.Update () [0x001ea] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkClient.cs:735
    14.   at UnityEngine.Networking.NetworkClient.UpdateClients () [0x00018] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkClient.cs:949
    15.   at UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () [0x00007] in D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkIdentity.cs:1074
    Update: oddly enough if I set breakpoints this error does not occur, seems like a timing issue.

    I'm also seeing this occasionally:

    Code (csharp):
    1.  
    2. Network configuration mismatch detected. The number of networked scripts on the client does not match the number of networked scripts on the server. This could be caused by lazy loading of scripts on the client. This warning can be disabled by the checkbox in NetworkManager Script CRC Check.
    3. UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    4. UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    5. UnityEngine.Logger:Log(LogType, Object)
    6. UnityEngine.Debug:LogWarning(Object)
    7. UnityEngine.Networking.NetworkCRC:ValidateInternal(CRCMessageEntry[], Int32) (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkCRC.cs:76)
    8. UnityEngine.Networking.NetworkCRC:Validate(CRCMessageEntry[], Int32) (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkCRC.cs:68)
    9. UnityEngine.Networking.NetworkClient:OnCRC(NetworkMessage) (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkClient.cs:889)
    10. UnityEngine.Networking.NetworkConnection:HandleReader(NetworkReader, Int32, Int32) (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkConnection.cs:467)
    11. UnityEngine.Networking.NetworkConnection:HandleBytes(Byte[], Int32, Int32) (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkConnection.cs:424)
    12. UnityEngine.Networking.NetworkConnection:TransportRecieve(Byte[], Int32, Int32) (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkConnection.cs:574)
    13. UnityEngine.Networking.NetworkClient:Update() (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkClient.cs:735)
    14. UnityEngine.Networking.NetworkClient:UpdateClients() (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkClient.cs:949)
    15. UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate() (at D:\work\coat.of.legs\dev\UnitySource\Unity-Technologies-networking-40b219054a68-v5.5\Runtime\NetworkIdentity.cs:1074)
     
    Last edited: Mar 29, 2017
  6. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    Another crash, but deeper this time:

    Code (csharp):
    1.  
    2. NullReferenceException
    3.   at (wrapper managed-to-native) UnityEngine.Component:get_gameObject ()
    4.   at UnityEngine.Component.GetComponents[NetworkBehaviour] () [0x00000] in <filename unknown>:0
    5.   at UnityEngine.Networking.NetworkIdentity.CacheBehaviours () [0x00000] in <filename unknown>:0
    6.   at UnityEngine.Networking.NetworkIdentity.OnStartClient () [0x00000] in <filename unknown>:0
    7.   at UnityEngine.Networking.ClientScene.OnObjectSpawnFinished (UnityEngine.Networking.NetworkMessage netMsg) [0x00000] in <filename unknown>:0
    8.   at UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) [0x00000] in <filename unknown>:0
    9.   at UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) [0x00000] in <filename unknown>:0
    10.   at UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) [0x00000] in <filename unknown>:0
    11.   at UnityEngine.Networking.NetworkClient.Update () [0x00000] in <filename unknown>:0
    12.   at UnityEngine.Networking.NetworkClient.UpdateClients () [0x00000] in <filename unknown>:0
    13.   at UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () [0x00000] in <filename unknown>:0
     
  7. JeremyUnity

    JeremyUnity

    Joined:
    Mar 4, 2014
    Posts:
    147
    Hi spaceman8,
    The networked scripts configuration mismatch error is usually a sign something is seriously wrong with your test setup, but it's possible there's an underlying bug here. It means the client and server are out of sync on the scripts they have available, usually meaning the client and server are on two incompatible builds. Be sure to clean out your standalone build and try again, and if the issue persists please submit a bug report with your project so we can check it out.
     
  8. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    When you say "something is seriously wrong with your test setup", what are some examples of what could be wrong that may be causing any number of the issues above?

    Thanks.
     
  9. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    Well., I think I solved it. Talk about chasing red herrings. Anyway, what was happening is that in my OnClientConnect handler (I've extended to override the default NetManager), I was checking to see if the ClientScene was ready and if not calling ClientScene.Ready, after all this is what the NetManager was doing. Then I start the game on the server which basically loads a new scene using ServerChangeScene. Now the docs say
    so naturally in my OnClientSceneChanged handler I was again checking to see if the ClientScene was ready and if not make it ready and herein lies the problem, the ClientScene was reporting as already being ready and therefor it was never participating in the new scene. To fix it, I removed the ready state handling from OnClientConnect and only do it in OnClientSceneChanged. I suspect though if I were to try and load another scene after the first I might have the same problem so I will get to that when it comes. This seems like a bug or the docs are wrong, not sure which.

    Lastly regarding the duplicate sceneId's, I'm not sure if this fixed it or not but I forced all of my assets to text mode and changed them all to 0, there were a couple that were non-zero. I have not see the duplicate scene ids since.

    Update: the docs in the quote above say "NetworkClient" but there is no Ready call in NetworkClient so I assume they mean ClientScene?
     
  10. spaceman8

    spaceman8

    Joined:
    Jan 6, 2017
    Posts:
    40
    Everything "appears" to be working but I am still receiving "Did not find target for sync message for X" messages, my scene has quite a few things in it so I probably just haven't noticed the items not updating properly yet.