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 webgovernor · Jan 24, 2016 at 09:55 PM · unity 5networkingmanagerlobby

Prevent NetworkLobbyManager from changing scenes.

Hello all,

Using the NetworkLobbyManager, lobbyScene and playScene must be populated to avoid errors.

If a game has been started and all clients are in the playScene, and a host quits or disconnects, then I'd like the clients to be redirected to a custom "Scores" scene.

Currently, when a host disconnects, the default NetworkLobbyManager behavior is to send the clients back to the lobby (which they cannot join as the host is gone).

Since this behavior, to me, does not make sense, I'd like to change it.

Part of the problem is that I also attempt to cleanup the NetworkManager (called Shutdown() then Destroy on the gameObject), otherwise subsequent matches throw all sorts of weird errors.

tl;dr: Is there a hook or someway I can change the default "switch to lobby on disconnect" behavior of UNET?

Thanks for your time.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Elethier · Nov 07, 2016 at 08:06 AM

The short answer is that there's no public hook within NetworkManager to stop the scene changing.

The good news is that there IS a workaround! The source code for NetworkManager is up on Bitbucket. Here's the version for the 5.4 branch. If you look at the source code, you can see that there are two spots where the scene manager is invoked:

  • The virtual function ServerChangeScene

  • The internal function ClientChangeScene

ClientChangeScene is called when the property offlineScene is set to anything besides empty string. It's also called when receiving a scene change message from the server with the name of the lobby scene. So if you subclass NetworkManager and make some adjustments, you won't change scenes no matter what connection events are occuring:

 using UnityEngine.Networking;
 
 public class MyNetworkingManager: NetworkingManager
 {
     private string originalLobbyScene;

     public MyNetworkingManager(): base()
     {
         offlineScene = "";
         lobbyScene = "myLobby"; // Name of the scene with the network manager
     }
 
     public override void ServerChangeScene(string sceneName)
     {
         // Do nothing
     }

     void Start()
     {
         originalLobbyScene = lobbyScene;
     }

     public override void OnStartClient(NetworkClient lobbyClient)
     {
         lobbyScene = originalLobbyScene; // Ensures the client loads correctly
     }

     public override void OnStopClient()
     {
          lobbyScene = ""; // Ensures we don't reload the scene after quitting
     }

     public override void OnStartServer()
     {
         lobbyScene = originalLobbyScene; // Ensures the server loads correctly
     }

     public override void OnStopServer()
     {
         lobbyScene = ""; // Ensures we don't reload the scene after quitting
     }
 }

(I should note, I suspect that putting offlineScene = ""; in the Start() function instead of the constructor will work, too. And I didn't run this code through a compiler, so let me know if there's any errors.)

With this solution you shouldn't see any scene changes occurring, at least for the version of the NetworkManager as of this writing. I'm using it in my game, and I haven't noticed any issues yet. If you want to use NetworkLobbyManager, just subclass NetworkLobbyManager instead of NetworkManager.

Comment
Add comment · Share
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
0

Answer by trojaon · Mar 08, 2018 at 01:49 PM

I have experienced the same issue using LobbyNetworkManager. My workaround solution was pretty much the same as Elethiers with the difference in:

         public override void OnStartServer()
         {
             lobbyScene = originalLobbyScene; // Ensures the server loads correctly
             base.OnStartServer();
         }
         public override void OnStopServer()
         {
             base.OnStartServer();
             lobbyScene = ""; // Ensures we don't reload the scene after quitting
         }
Comment
Add comment · Share
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

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

On NetworkLobbyManager override, base.OnLobbyServerCreate[Lobby/Game]Player() return null. Is that normal ? 0 Answers

How to call NetworkClient.Ready() ? 1 Answer

Disconnected from lobby manager if game is already started. 0 Answers

UNET shouldn't disconnect 0 Answers

OnStart ___ vs OnLobbyStart ___ methods from NetworkManager and NetworkLobbyManager 1 Answer


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