- Home /
NetworkIdentity of NetworkLobbyPlayer has assetID 00000 zero after UnityEditor lost focus
Hi, I'm implementing a Lobby by using the NetworkLobbyManager. The according NetworkLobbyPlayer is spawned automatically, because Auto-Create-Player is checked on the LobbyManager.
Everything works fine until I lose the focus of the Unity Editor in Windows (to start the game on an other instance of Unity or on the standalone). When coming back to Unity then the assetId of the NetworkIdentiy of the LobbyPlayer instantly changes to 000000... (It's also well described in this post: https://forum.unity.com/threads/networkidentitys-asset-id-resetting-to-zero-when-alt-tabbing-to-editor.486927/ )
The problem occurs only with the LobbyPlayerPrefab, but not with the GamePlayerPrefab (in the PlayScene).
Does somebody know what's happening there. Is it maybe a problem with resetting the assetId on EditorWindow.OnFocus()?
Also thought, it could be a problem, that you have to register the prefab on the client scene. But I guess that is done correctly by the LobbyManager already, because until leaving the Unity Editor Window everything works normal.
Answer by BBIT-SOLUTIONS · Nov 12, 2018 at 11:22 AM
Found a workaround.
It is not very handy but it works and you can keep focusing on development and debugging without getting strange assetId errors.
Just start a coroutine in OnClientEnterLobby() where you temporarily store the id, when it is valid. And if it is invalid (000...) just recreate the prefab with the same assetId
NetworkHash128 tmpAssetId;
IEnumerator AssetIdChecker(){
WaitForSeconds myWait = new WaitForSeconds(1f);
while(true){
if(isClient){
if(GetComponent<NetworkIdentity>().assetId.IsValid()){
tmpAssetId = GetComponent<NetworkIdentity>().assetId;
}else{ //after lost focus of Unity Editor, reassign
ClientScene.RegisterPrefab(this.gameObject, tmpAssetId);
}
}
yield return myWait;
}
}