I amextending the NetworkLobbyManager
to create a game lobby:
public class NLMExtender : NetworkLobbyManager
{
public override void OnLobbyStartHost()
{
GameObject.FindWithTag("MultiplayerRoom").GetComponent<MultiplayerRoom>().isHost = true;
}
}
I create a match like this which creates lobby players on the scene:
/// <summary>
/// Create a match
/// </summary>
public void CreateMatch()
{
networkMatch = gameObject.AddComponent<NetworkMatch>();
CreateMatchRequest create = new CreateMatchRequest();
create.name = "MS_" + Guid.NewGuid().ToString("N");
create.size = 2;
create.advertise = true;
create.password = "";
networkMatch.CreateMatch(create, OnMatchCreate);
}
/// <summary>
/// When match is being created
/// </summary>
/// <param name="matchResponse"></param>
public void OnMatchCreate(CreateMatchResponse matchResponse)
{
if (matchResponse.success)
{
matchInfo = new MatchInfo(matchResponse);
Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
networkLobbyManager.StartHost(matchInfo);
}
else {
Debug.LogError("Create match failed");
}
}
And I join a room like this which does not create the lobby players on the client:
/// <summary>
/// Connects to the lobby
/// </summary>
public void ConnectToRoom(GameObject gameList, MatchDesc match)
{
networkMatch = gameObject.AddComponent<NetworkMatch>();
gameList.SetActive(false);
networkMatch.JoinMatch(match.networkId, "", OnMatchJoined); // connect to the room
}
/// <summary>
/// When a lobby has been joined
/// </summary>
/// <param name="matchJoin">Result of joining a lobby</param>
public void OnMatchJoined(JoinMatchResponse matchInfo)
{
if (matchInfo.success)
{
networkLobbyManager.StartClient(new MatchInfo(matchInfo));
}
else
{
Debug.LogError("Join match failed");
}
}
Is there anything here that can be the reason for this? Because when I added the NetworkLobbyManager
to the game object trough the editor it worked, but not when I extend this class to my own script (for the ability to override). Am I missing something that automatically happens when doing it trough the editor?
This is how it looks in the editor today:
The error message which most probably is related to my problem:
RegisterHandler id:45
handler:OnClientAddPlayerFailedMessage
UnityEngine.Networking.NetworkManager:StartClient(MatchInfo)
MultiplayerRoom:OnMatchJoined(JoinMatchResponse)
(at Assets/Scripts/GUI/Menus/Multiplayer/MultiplayerRoom.cs:81)
UnityEngine.Networking.Match.c__Iterator0`1:MoveNext()