How to create a custom network lobby manager with unet?
I had a really hard time creating a custom network manager because the documentation for it was either hard to find or not existing at all.
Since this community has given so much to me, I want to give something back.
Below you will find a quick guide for creating your own custom network manager and network lobby manager!
Answer by Sgt_Gemini · Dec 19, 2017 at 06:25 PM
Creating a Custom Network Manager
If your game has a lobby you should use the options for NetworkLobbyManager. If not, you can use the normal NetworkManager.
The Steps to freedom!
1: Start by creating a new C# script. You can call it "CustomNetworkManager" or "CustomNetworkLobbyManager".
2: Now change the class type from "MonoBehavior" to "NetworkManager" or "NetworkLobbyManager" depending on your needs.
3: Add the following statements in the beginning of your script: "using UnityEngine.Networking".
4: In your hierarchy, create a new empty gameobject. Rename it to whatever you called your network manager script.
5: Add your custom network manager script to the empty gameobject.
6: Add a Network Manager HUD component to your gameobject (if you don't have your own HUD).
7: Make sure you don't have any other network managers running. Your custom network manager will do exactly the same as the normal network managers.
8: Now you have access to the specific methods of the network manager. Remember to make sure you add the word "override" to your method and be aware that this will stop the normal method from working. This means that if you override a method you have to make sure to add whatever that method did in your own version.
Note: Your custom network manager should be added to the first scene that runs, just like a normal network manager.
A few examples
You will ofcourse have to add methods to your custom network manager (not random scripts) for them to work.
This is how to setup the script
using UnityEngine.Networking;
public class CustomNetworkLobbyManager : NetworkLobbyManager {
// Your code here
}
public override void OnServerAddPlayer (NetworkConnection conn, short playerControllerId) {
// your code here
}
public override void OnServerDisconnect (NetworkConnection conn) {
// Your code here
}
Here you can see the methods
NetworkManager
NetworkLobbyManager
Final notes
I am by no means an expert on UNET. If you find any mistakes in this guide or have any inputs that you feel should be in here please comment and I will fix or add it!
Best of luck with your networked project! :)
Gemini
Warrior Games
Answer by DoritoDog · Oct 10, 2019 at 05:09 AM
If you also want to override the singleton, use:
public static new CustomNetworkManager singleton { get { return NetworkManager.singleton as CustomNetworkManager; } }
Your answer
Follow this Question
Related Questions
[Multiplayer Lobby] NetworkManager has a NetworkIdentity component 1 Answer
Modifying Unity Network Lobby 0 Answers
Exiting a UNET lobby causes future ClientRPC calls to be ignored. 1 Answer
Match options in unet for servers list. 0 Answers
How can players select their own preferences in the lobby? 1 Answer