Spawning the player prefabs only after a required number of clients join

Hello, I’m working on a project right now and I need to spawn the player prefabs only after a required number of clients have joined. Since I’m new to networking I would really appreciate if someone could explain me how to do that :slight_smile: . As far as I understand I need to make a custom network manager script have a int that holds the number of clients connected. And when it reaches the required number it spawns the players. So i created a custom Network Manager and I have the int value, but I cant figure out what function is called when a client connects :d . This doesnt work

int PlayerCount = 0;
public override void OnServerConnect(NetworkConnection conn) // if I do OnClientConnect It still doesnt work
{
base.OnClientConnect(conn);
PlayerCount++;
Debug.Log(PlayerCount);
}

This Code is in the NetworkManager script by the way.

Another thing is actually spawning the player. I think a different method of spawning (not instantiate) is used to create a player in a networked scene and you need to register it or something, but I think I can figure that out myself :). Thanks for the help :* .

There is a ‘Network Lobby’ asset on the store, created by Unity. It does exactly what you are asking for and comes with the source code (even though it’s kinda complex).

1 Like

Cool, I will check it out. ty for answer

Ok, so I checked it out and its kinda broken :/. As soon as I import the asset an error appears: Assets/Lobby/Scripts/Lobby/LobbyManager.cs(72,30): error CS0117: SceneManager' does not contain a definition for GetSceneAt’
It says that the scene manager doesnt contain a definition of GetSceneAt, but it should. You can even find the documentation about that function: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.GetSceneAt.html
Anyway, thanks for the answer I will try solving this problem some other way:) .

You probably need the latest Unity version.

I have the latest version.

Ok, so I fixed this problem with the Lobby Manager that vis2k commented about. If you have the same problem with the SceneManager.GetSceneAt it’s because you have a script called SceneManager, change the name and the functions in the SceneManager will start working.