Network connection issue started seemingly out of the blue - need help

Hi,. I’ve been pulling my hair out over this and I’m not quite sure what to check next. I have a fairly basic game setup with networking support and everything was working fine, today however I just noticed a few issues that were not there before. I’m currently using the NetworkManager HUD for testing.

1> If I select LAN Host on a standalone build I now have to click Client Ready for the game to start, before I just clicked LAN Host and when I am running in the Editor this still is the case, my player prefab would get created and off it goes.

2> If I start the host in the standalone version and then run the game in the editor and click LAN Client I can see that the client connects but it never spawns my player prefab, nor can I see the server player however I can see an object appear that I can optionally spawn on the host side when pushing a button.

If I do this the other way around and host in the editor and use the standalone as the client then everything works as expected which is usually how I test and therefor I am not sure what change I made that would have broke this. I am not getting any errors in the console and I have put the NetworkManager into debug mode but do not see any warnings or error messages of any kind.

I have made a number of changes such as adding Anima2D bone animations, switching to a bump + light based sprite material, created some more assets etc… but nothing regarding networking so I am not sure what exactly happened.

If you have any ideas or suggestions I would love to hear them.

Thanks!

Doing a little more digging, I built a development build of the standalone and tried to host a game, luckily I found a null reference exception that is more than likely causing this issue… However! Its in Unity code and am not sure what is causing it, I’ll keep digging but here is the exception:

NullReferenceException: Object reference not set to an instance of an object
  at UnityEngine.Networking.NetworkTransform.SerializeMode3D (UnityEngine.Networking.NetworkWriter writer) [0x00062] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkTransform.cs:256
  at UnityEngine.Networking.NetworkTransform.OnSerialize (UnityEngine.Networking.NetworkWriter writer, Boolean initialState) [0x0006f] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkTransform.cs:200
  at UnityEngine.Networking.NetworkIdentity.UNetSerializeAllVars (UnityEngine.Networking.NetworkWriter writer) [0x00015] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:454
  at UnityEngine.Networking.NetworkServer.SendSpawnMessage (UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Networking.NetworkConnection conn) [0x000f2] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1395
  at UnityEngine.Networking.NetworkServer.ShowForConnection (UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Networking.NetworkConnection conn) [0x00013] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1191
  at UnityEngine.Networking.NetworkConnection.AddToVisList (UnityEngine.Networking.NetworkIdentity uv) [0x00010] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:551
  at UnityEngine.Networking.NetworkIdentity.AddObserver (UnityEngine.Networking.NetworkConnection conn) [0x000f0] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:845
  at UnityEngine.Networking.NetworkServer.SetClientReadyInternal (UnityEngine.Networking.NetworkConnection conn) [0x00104] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1144
  at UnityEngine.Networking.NetworkServer.SetClientReady (UnityEngine.Networking.NetworkConnection conn) [0x00007] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1106
  at UnityEngine.Networking.NetworkManager.OnServerReady (UnityEngine.Networking.NetworkConnection conn) [0x00029] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:1009
  at Spaceman.Net.ExtendedNetworkManager.OnServerReady (UnityEngine.Networking.NetworkConnection conn) [0x00018] in D:\work\coat.of.legs\dev\projects\SpaceMan2D\Assets\Scripts\Net\ExtendedNetworkManager.cs:37
  at UnityEngine.Networking.NetworkManager.OnServerReadyMessageInternal (UnityEngine.Networking.NetworkMessage netMsg) [0x0001e] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:853
  at UnityEngine.Networking.NetworkConnection.InvokeHandler (Int16 msgType, UnityEngine.Networking.NetworkReader reader, Int32 channelId) [0x00086] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:217
  at UnityEngine.Networking.NetworkServer.InvokeHandlerOnServer (UnityEngine.Networking.ULocalConnectionToServer conn, Int16 msgType, UnityEngine.Networking.MessageBase msg, Int32 channelId) [0x0003b] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1639
  at UnityEngine.Networking.ULocalConnectionToServer.Send (Int16 msgType, UnityEngine.Networking.MessageBase msg) [0x0000b] in C:\buildslave\unity\build\Extensions\Networking\Runtime\LocalConnections.cs:83
  at UnityEngine.Networking.ClientScene.Ready (UnityEngine.Networking.NetworkConnection conn) [0x0005b] in C:\buildslave\unity\build\Extensions\Networking\Runtime\ClientScene.cs:302
  at UnityEngine.Networking.NetworkManager.OnClientConnect (UnityEngine.Networking.NetworkConnection conn) [0x0000e] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:1112
  at Spaceman.Net.ExtendedNetworkManager.OnClientConnect (UnityEngine.Networking.NetworkConnection conn) [0x00018] in D:\work\coat.of.legs\dev\projects\SpaceMan2D\Assets\Scripts\Net\ExtendedNetworkManager.cs:71
  at UnityEngine.Networking.NetworkManager.OnClientConnectInternal (UnityEngine.Networking.NetworkMessage netMsg) [0x0007d] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:919
  at UnityEngine.Networking.NetworkConnection.InvokeHandler (UnityEngine.Networking.NetworkMessage netMsg) [0x0002c] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:228
  at UnityEngine.Networking.LocalClient.ProcessInternalMessages () [0x000dc] in C:\buildslave\unity\build\Extensions\Networking\Runtime\LocalClient.cs:142
  at UnityEngine.Networking.LocalClient.Update () [0x00002] in C:\buildslave\unity\build\Extensions\Networking\Runtime\LocalClient.cs:69
  at UnityEngine.Networking.NetworkClient.UpdateClients () [0x00024] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkClient.cs:950
  at UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () [0x00006] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:1089

(Filename: C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkTransform.cs Line: 256)

Looking at the UNET source here: https://bitbucket.org/Unity-Technologies/networking/src/40b219054a6823f92874ed3017e64dac0c41b61c/Runtime/NetworkTransform.cs?at=5.5&fileviewer=file-view-default line, 256 doesnt look like an exception is possible. I’m using version 5.5 of Unity and this is the 5.5 branch of UNET code.

I’ve also double checked all of my NetworkTransforms that are set to syncMode3D have a 3D rigidbody attached.

I found someone with an extremely similar problem, but no solutions: Getting a NullReferenceException on NetworkManager only in standalone when spawning Player Objects - Questions & Answers - Unity Discussions

:frowning:

I’m abandoning this, I feel the HLAPI is not a good fit for my game anyway since I really need it to be P2P and with these sorts of issues its a no brainer. Time to dig into the LLAPI or maybe Photon. Thanks for looking.

I have seen similar issues before and it’s usually due to trying to spawn a prefab, instead of a instantiated object.

playerObject = Instantiate(playerPrefab) as GameObject;
NetworkServer.SpawnWithClientAuthority(playerPrefab, connectionToClient);

Note that here we try to spawn playerPrefab and not the playerObject.
There is a fix coming in a future release that makes the error message more readable.

I don’t think its my player object at all, I am using a CharacterController which is what the NetworkTransform is set to use, not syncMode3D which is what the error/stack is suggesting.