- Home /
Player duplication when testing on android mobile Matchmaker system
Hello fine unity devs! I am developing a top down shooter multiplayer mobile game for android. My Unity version is 2018.3.0f2 and I am using NetworkLobbyManager to handle my lobby, Matchmaker and relay services for matchmaking. My lobby settings look like this: Link for picture of lobby settings
I get a weird player duplication glitch where out of 1 lobby player I get 2 ingame players when scene changes from offline to online, therefore creating more players than the lobby allows it in the settings where max players count is 4 players and in my online scene spawns 7 players as shown in the picture below: LinkForGlitchPicture
What i tried so far to solve this issue:
manually creating players with OnClientConnect, OnLobbyServerCreateGamePlayer and OnClientSceneChanged and disabled autocreate players tickbox in lobby but with no luck, issue persists. Code for manually creating players:
public class MyLobby : NetworkLobbyManager { public override void OnClientConnect(NetworkConnection conn) { Debug.Log("Caling OnClientConnect"); ClientScene.Ready(conn); ClientScene.AddPlayer(0); } public override void OnClientSceneChanged(NetworkConnection conn) { base.OnClientSceneChanged(conn); Debug.Log("Caling OnClientSceneChanged"); } }
tried to spawn a dupe empty game object when a player with same connection id was detected, didnt work properly. It sucessfully created dupes for duplicate player objects but it gave you control over that empty gameobject instead of the real/local player object. Which resulted in a black screen, because the dupes are empty objects and have no camera on them.
Code for spawning duped empty player objects:
public class MyLobby : NetworkLobbyManager
{
//we use this variable to store connection id
public int netCon=10;
public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
{
//we check if the netcon value is different than the player that is being created, if its not then we have a dupe
if (netCon != conn.connectionId)
{
GameObject _temp = Instantiate(PlayerCharacter, startPositions[conn.connectionId].position, startPositions[conn.connectionId].rotation);
netCon = conn.connectionId;
Debug.Log("Value of netcon is: " + netCon);
return _temp;
}
else
{
GameObject dupe_temp = Instantiate(Dupe);
Debug.Log("Spawned a dupe player");
return dupe_temp;
}
}
}
Any help with this issue would be much appreciated!
Answer by mathias512 · Jul 13, 2019 at 09:36 AM
Looked for a viable solution to this problem for a long time now (over 1 month), didnt find anything that could help. I managed to finally solve it by switching to PUN2. Everyone that has problems with Unet I recommend ditching it as soon as possible and not wasting time on fixing problems with Unet. I dont mean to sound toxic but Unet by now is basically so broken it cant be used for the simplest of network games.
Your answer
Follow this Question
Related Questions
Matchmaking on Android, CLient doesn't create PlayerPrefab 0 Answers
Mobile transparency issue 0 Answers
Semaphore.WaitForSignal is causing so much lag on Android!!! Help!!! 1 Answer
AV Pro Video Playback Rewinding Issue -Android 0 Answers
Why on the mobile do the elements seem to have a very unstable position? 0 Answers