I am using the LobbyManager asset as found on the Unity Store. Specifically, I am using the one integrated with the Meteroid (Asteroids) game. I have edited only one thing so far from the original scripts.
I have edited the NetworkLobbyHook.cs script to allow me to change player’s colors, and their goal’s colors. Along with this it changes their object’s names.
Here is my changes:
using UnityEngine;
using Prototype.NetworkLobby;
using System.Collections;
using UnityEngine.Networking;
[NetworkSettings (channel=0, sendInterval=0.1f)]
public class NetworkLobbyHook : LobbyHook
{
public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer)
{
LobbyPlayer lobby = lobbyPlayer.GetComponent<LobbyPlayer>();
CTFColorChangerScript player = gamePlayer.GetComponent<CTFColorChangerScript>();
CTFGoalColorChangerScript goal = GameObject.FindGameObjectWithTag ("Goal" + (lobby.slot + 1)).GetComponent<CTFGoalColorChangerScript>();
if( goal != null ) {
goal.gameObject.GetComponent<Renderer>().material.color = lobby.playerColor;
goal.goalColor = lobby.playerColor;
goal.ownerName = lobby.playerName;
player.name = lobby.playerName;
player.playerName = lobby.playerName;
player.color = lobby.playerColor;
}
}
}
For my channels I have tried using Reliable State Update, Reliable Sequenced, and Unreliable. Channel #0 is currently Reliable Sequenced. Channel #1 is Unreliable.
The issue is, when the player connects, we have no issues changing colors or names. However when both players ready up, and the game advances to the game scene, there is a chance that the client will become the host as well. The client’s object is still spawned in the scene, but his color, name, and controls are all disregarded. Using Debugs, it is very clear that when the OnLobbServerSceneLoadedForPlayer() is broken, it is not being called on the client whatsoever. The debugs both show up on the Host, and the host gets the error:
Assets/WRAPPER/SampleScenes/Scripts/NetworkLobbyHook.cs:16)
Prototype.NetworkLobby.LobbyManager.OnLobbyServerSceneLoadedForPlayer (UnityEngine.GameObject lobbyPlayer, UnityEngine.GameObject gamePlayer) (at Assets/WRAPPER/Lobby/Scripts/Lobby/LobbyManager.cs:333)
UnityEngine.Networking.NetworkLobbyManager.SceneLoadedForPlayer (UnityEngine.Networking.NetworkConnection conn, UnityEngine.GameObject lobbyPlayerGameObject) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkLobbyManager.cs:147)
UnityEngine.Networking.NetworkLobbyManager.OnServerSceneLoadedMessage (UnityEngine.Networking.NetworkMessage netMsg) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkLobbyManager.cs:463)
UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:453)
UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:409)
UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:561)
UnityEngine.Networking.NetworkServer.OnData (UnityEngine.Networking.NetworkConnection conn, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:753)
UnityEngine.Networking.NetworkServer+ServerSimpleWrapper.OnData (UnityEngine.Networking.NetworkConnection conn, Int32 receivedSize, Int32 channelId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1845)
UnityEngine.Networking.NetworkServerSimple.HandleData (Int32 connectionId, Int32 channelId, Int32 receivedSize, Byte error) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServerSimple.cs:382)
UnityEngine.Networking.NetworkServerSimple.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServerSimple.cs:248)
UnityEngine.Networking.NetworkServer.InternalUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:705)
UnityEngine.Networking.NetworkServer.Update () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:655)
UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1060)
As it seems, it can’t find the goal. Probably because it’s trying to find a goal when it already did that for the host. I’m really not sure at this point. The client also doesn’t spawn a player object at all, other than the host’s. The host’s scene has a player prefab (default settings of that prefab), spawned where he should be, and the object’s name has been changed to “”.
Any ideas?