Hi, I’m trying to make my own LobbyManager and LobbyPlayer scripts. Right now they “almost” work since both host and client can connect to the game but I get this error message and then the player prefabs don’t spawn in the game scene.
NetworkLobbyManager OnServerReadyToBeginMessage invalid playerControllerID 255
UnityEngine.Networking.NetworkIdentity : UNetStaticUpdate()
Wondering if anyone has run into this particular error since I haven’t been able to find it online. Below is my code for the LobbyManager. LobbyPlayer currently just sends ready to begin message at start and that’s it. The way LobbyManager works: 1) a button is pressed in the main menu and runs FindInternetMatch(), 2.a) if there is a match, it joins automatically, all players get ready and the match starts, or 2.b) if there is no match, it creates one and hosts it.
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine.Networking.Types;
using System.Collections;
public class CustomLobbyManager : NetworkLobbyManager
{
public GameObject playButton;
void Start()
{
playButton.SetActive(true);
NetworkManager.singleton.StartMatchMaker();
}
//call this method to request a match to be created on the server
public void CreateInternetMatch(string matchName)
{
NetworkManager.singleton.matchMaker.CreateMatch(matchName, 4, true, "", "", "", 0, 0, OnInternetMatchCreate);
}
//this method is called when your request for creating a match is returned
private void OnInternetMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
{
if (success)
{
MatchInfo hostInfo = matchInfo;
NetworkServer.Listen(hostInfo, 9000);
NetworkManager.singleton.StartHost(hostInfo);
}
else
{
Debug.LogError("Create match failed");
}
}
//call this method to find a match through the matchmaker
public void FindInternetMatch(string matchName)
{
NetworkManager.singleton.matchMaker.ListMatches(0, 10, matchName, true, 0, 0, OnInternetMatchList);
}
//this method is called when a list of matches is returned
private void OnInternetMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
{
if (success)
{
if (matches.Count != 0)
{
//join the last server (just in case there are two...)
NetworkManager.singleton.matchMaker.JoinMatch(matches[matches.Count - 1].networkId, "", "", "", 0, 0, OnJoinInternetMatch);
}
else
{
CreateInternetMatch("First");
}
}
else
{
Debug.LogError("Couldn't connect to match maker");
}
}
//this method is called when your request to join a match is returned
private void OnJoinInternetMatch(bool success, string extendedInfo, MatchInfo matchInfo)
{
if (success)
{
MatchInfo hostInfo = matchInfo;
NetworkManager.singleton.StartClient(hostInfo);
}
else
{
Debug.LogError("Join match failed");
}
}
public override void OnLobbyServerPlayersReady()
{
ServerChangeScene(playScene);
}
public override void OnLobbyClientSceneChanged(NetworkConnection conn)
{
if (SceneManager.GetSceneAt(0).name == lobbyScene)
{
playButton.SetActive(true);
}
else
{
playButton.SetActive(false);
}
}
public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
{
//This hook allows you to apply state data from the lobby-player to the game-player
//just subclass "LobbyHook" and add it to the lobby object.
//if (_lobbyHooks)
// _lobbyHooks.OnLobbyServerSceneLoadedForPlayer(this, lobbyPlayer, gamePlayer);
return true;
}
public override void OnServerConnect(NetworkConnection conn)
{
Debug.Log(conn);
}
}
Thanks in advance!