Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DarthMohawk · Feb 21, 2016 at 04:21 PM · bug-perhaps

ServerReturnToLobby() not workiing

Unfortunately I don't have much more information than the title

In my LobbyManager : NetworkLobbyManager I make a call to ServerReturnToLobby(), I keep getting this error

 SetClientOwner m_ClientAuthorityOwner already set!
 UnityEngine.Networking.NetworkLobbyManager:ServerReturnToLobby()
 LobbyManager:PlayerDead(PlayerControllerComponent) (at Assets/Scripts/LobbyManager.cs:104)
 PlayerControllerComponent:CmdKillPlayer() (at Assets/Scripts/PlayerControllerComponent.cs:247)
 PlayerControllerComponent:CallCmdKillPlayer()
 PlayerControllerComponent:OnTriggerEnter2D(Collider2D) (at Assets/Scripts/PlayerControllerComponent.cs:260)

I cannot find any information about why this would be. There is nothing in the documentation, and all questions on this forum related to this issue haven't been answered yet

Here is my code, the call is being made in CheckIfGameOver() I also tried a bunch of other calls: SendReturnToLobby(), ServerReturnToLobby(), and ServerChangeScene(lobbyScene) all cause the same issue

I have a feeling I don't have something setup correctly, but I can't figure out what it is

NOTE: In order to reduce the size of this post I removed some methods that don't have anything to do with scene transitions. I can post more if needed

 public class LobbyManager : NetworkLobbyManager
 {
     private class Player
     {
         public int connectionId;
         public bool isAlive;
         public int score;
     }

     public static LobbyManager _instance;

     public RectTransform lobbyGui;
     public RectTransform menuGui;
     public RectTransform countdownGui;
     public Text countdownText;
     public float countdownTime = 5.0f;

     private List<NetworkLobbyPlayer> _players = new List<NetworkLobbyPlayer>();
     private List<Player> connectedPlayerIds = new List<Player>();         //TODO: limit number of players
     private RectTransform _currentPanel;
     private Vector3[] _playerSpawnVectors = new Vector3[4]
     {
         new Vector3(1.0f, 11.0f, 0.0f),
         new Vector3(1.0f, 1.0f, 0.0f),
         new Vector3(12.0f, 1.0f, 0.0f),
         new Vector3(12.0f, 11.0f, 0.0f)
     };

     private bool sceneLoaded = false;
     private int _gameEndCall = 0;

     public GameObject bombUpgrade;
     public GameObject laserUpgrade;
     public GameObject kickUpgrade;
     public GameObject lineUpgrade;
     public GameObject radioactiveUpgrade;

     public GameObject floor;
     public GameObject destructible;
     public GameObject indestructible;
     public GameObject[] playerAnimations;
     private BoardCreator boardCreator;

     void Start()
     {
         _instance = this;
         _currentPanel = menuGui;
     }


     // **************SERVER**************
     public override void OnLobbyStartServer()
     {
         base.OnLobbyStartServer();
         connectedPlayerIds.Clear();
     }

     public override void OnLobbyServerConnect(NetworkConnection conn)
     {
         base.OnLobbyServerConnect(conn);

         if (conn.address != "localServer")
         {
             connectedPlayerIds.Add( new Player() { connectionId = conn.connectionId, isAlive = true, score = 0 } );
         }
         
     }

     public override void OnLobbyServerDisconnect(NetworkConnection conn)
     {
         base.OnLobbyServerDisconnect(conn);
         connectedPlayerIds.Remove(connectedPlayerIds.Where(x => x.connectionId == conn.connectionId).FirstOrDefault());
     }

     public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection networkConnection, short playerControllerId)
     {
         int i = getSlotIndex(networkConnection.connectionId);

         GameObject newPlayer = (GameObject)Instantiate(playerPrefab, Vector2.zero, Quaternion.identity);
         newPlayer.transform.position = _playerSpawnVectors[i];
         newPlayer.GetComponent<PlayerControllerComponent>().playerIndex = i;

         NetworkServer.Spawn(newPlayer);
         return newPlayer;
     }

     public void PlayerDead(PlayerControllerComponent player)
     {
         SpawnUpgradeInRandomLocation(UpgradeType.Bomb, player.maxNumBombs - 1);
         SpawnUpgradeInRandomLocation(UpgradeType.Laser, player.bombParams.radius - 2);
         SpawnUpgradeInRandomLocation(UpgradeType.Kick, player.bombKick);
         SpawnUpgradeInRandomLocation(UpgradeType.Line, player.bombLine);

         connectedPlayerIds[player.playerIndex].isAlive = false;
         NetworkServer.Destroy(player.gameObject);

         CheckIfGameOver();
     }

     private void CheckIfGameOver()
     {
         if (connectedPlayerIds.Where(x => x.isAlive).Count() == 1)
         {
             connectedPlayerIds.Where(x => x.isAlive).First().score++;
             connectedPlayerIds.Where(x => x.isAlive).First().isAlive = false;
         }

         if (connectedPlayerIds.Where(x => x.isAlive).Count() == 0){
             ServerReturnToLobby(); // This call doesn't work for some reason
             Debug.Log("GAME OVER!");
         }
     }

     public override bool OnLobbyServerSceneLoadedForPlayer(GameObject gameObject1, GameObject gameObject2)
     {
         if (!sceneLoaded)
             SpawnBoard();
         sceneLoaded = true;
         return true;
     }

     public override void OnLobbyServerPlayersReady()
     {
         foreach (LobbyPlayer player in lobbySlots)
         {
             if (player != null)
             {
                 if (!player.readyToBegin)
                 {
                     return;
                 }
             }
         }

         StartCoroutine(CountDownCoroutine());
     }

     public IEnumerator CountDownCoroutine()
     {
         float remainingTime = countdownTime;
         int floorTime = Mathf.FloorToInt(remainingTime);

         while (remainingTime >= -1)
         {
             yield return null;

             remainingTime -= Time.deltaTime;
             int newFloorTime = Mathf.FloorToInt(remainingTime);

             if (newFloorTime != floorTime)
             {
                 floorTime = newFloorTime;

                 foreach (LobbyPlayer player in lobbySlots)
                 {
                     if (player != null)
                     {
                         player.RpcUpdateCountdown(floorTime);
                     }
                 }
             }
         }

         ServerChangeScene(playScene);
     }

     public void KickPlayer(NetworkConnection conn)
     {
         conn.Disconnect();
     }

     // **************CLIENT**************

     public override void OnLobbyClientEnter()
     {
         base.OnLobbyClientEnter();
         ChangePanel(lobbyGui);
     }

     private int getSlotIndex(int connectionId)
     {
         int i = 0;
         foreach (var player in connectedPlayerIds)
         {
             if (player.connectionId == connectionId)
                 return i;
             i++;
         }

         Debug.LogError("No matching playerControllerId in slots");
         throw new ArgumentOutOfRangeException();
     }


     public override void OnLobbyClientExit()
     {
         base.OnLobbyClientExit();
         ChangePanel(menuGui);
     }

     public override void OnLobbyClientSceneChanged(NetworkConnection conn)
     {
         base.OnLobbyClientSceneChanged(conn);
         _currentPanel.gameObject.SetActive(false);
     }

     // **************GUI**************

     public void ChangePanel(RectTransform newPanel)
     {
         if (_currentPanel != null)
         {
             _currentPanel.gameObject.SetActive(false);
         }

         if (newPanel != null)
         {
             newPanel.gameObject.SetActive(true);
         }

         _currentPanel = newPanel;
     }


     // **************PLAYER LIST**************

     public void AddPlayer(LobbyPlayer player)
     {
         _players.Add(player);

     }

     public void RemovePlayer(LobbyPlayer player)
     {
         _players.Remove(player);
     }
 }
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Feb 21, 2016 at 10:10 AM 0
Share

Post your code.

avatar image DarthMohawk meat5000 ♦ · Feb 22, 2016 at 10:12 PM 0
Share

@meat5000 Thanks for the response, I posted the code

avatar image DarthMohawk · Feb 26, 2016 at 08:27 PM 0
Share

@crazyNight @$$anonymous$$ikeNewall @meat5000 Hey all, I hate to bug you guys, but I really need some help with this. This issue is still causing me problems and it is holding up my project. Any help will be appreciated

avatar image $$anonymous$$ · Feb 27, 2016 at 11:45 PM 0
Share

I'm seeing this as well, even in the stock Network Game Lobby (beta) asset. Consider filing a bug report if you haven't.

avatar image TwoTen $$anonymous$$ · Jun 13, 2016 at 10:24 AM 0
Share

Any fix yet? im having this exact issue?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5 tree creator not working correctly. 0 Answers

Google Cardboard 0.6 SDK becomes blurry on iOS devices 0 Answers

When opening, Unity won't load until I terminate a powershell process 0 Answers

Is it a rendering bug / artifact? 0 Answers

I'm having trouble opening any sort of project 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges