- Home /
How to fix OnObjSpawn netId: 1 has invalid asset Id when using Lobby example in existing project
I'm trying to add network lobby to my game. I started trying to create a lobby from scratch using the sample in the Asset Store, but I kept running into an error. I'm now trying this with the sample directly imported into my project. I run a built copy locally and run one in the editor. Then I use the editor one to host and join from the built copy. After clicking the Join on each player, it switches to the game and gives the following error on the built copy:
WindowsPlayer(XXXXXXXX) OnObjSpawn netId: 1 has invalid asset Id UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object) UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) UnityEngine.Logger:Log(LogType, Object) UnityEngine.Debug:LogError(Object) UnityEngine.Networking.ClientScene:OnObjectSpawn(NetworkMessage) (at C:\buildslave\unity\build\Extensions\Networking\Runtime\ClientScene.cs:516) UnityEngine.Networking.NetworkConnection:HandleReader(NetworkReader, Int32, Int32) (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:469) UnityEngine.Networking.NetworkConnection:HandleBytes(Byte[], Int32, Int32) (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:425) UnityEngine.Networking.NetworkConnection:TransportReceive(Byte[], Int32, Int32) (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:576) UnityEngine.Networking.NetworkClient:Update() (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkClient.cs:753) UnityEngine.Networking.NetworkClient:UpdateClients() (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkClient.cs:965) UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate() (at C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:1091)
(Filename: C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs Line: 516)
There are actually two of these messages for objects with netIds 1 and 2. Based on debugging it looks like these two objects are in fact the LobbyPlayers, which should already be registered, so there should be no need to call ClientScene.RegisterPrefab (nor does calling it change anything). I've also found that in between OnLobbyServerCreateLobbyPlayer where the player is created and OnLobbyServerSceneLoadedForPlayer when the game scene is being loaded the assetId on the player's NetworkIdentity goes from a normal hash value to all zeroes, which I believe is what is causing this.
I've imported the sample into a new project and it works just fine, so it's only in my project that this is an issue. Furthermore, if I test this with both instances as built players (thus removing the editor from the equation), I don't get the error in my project. However, I obviously want this to be able to work with the editor as a host, so I can debug other things. Does anyone have any ideas about what may be causing this error in these weird scenarios?