First of all, I have searched for these and I’m getting pretty desperate by now, haha.
How do I send messages from client to server just like how server can do that with NetworkServer.Send?
How do I reply to broadcast, or send message to a specific IP address?
Why is the NetworkClient I get from MyNetworkManager.singleton.StartHost() or StartClient() null? (MyNetworkManager is derived from NetworkManager)
Why do I get this error when calling ClientServer.AddPlayer(netId) and how to fix it?
“Must call AddPlayer() with a connection the first time to become ready.”
Why do I get NullReferenceException when all my arguments aren’t null?
Error Message
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Networking.ClientScene.InternalAddPlayer (UnityEngine.Networking.NetworkIdentity view, Int16 playerControllerId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:121)
UnityEngine.Networking.LocalClient.AddLocalPlayer (UnityEngine.Networking.PlayerController localPlayer) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/LocalClient.cs:85)
UnityEngine.Networking.NetworkServer.SetupLocalPlayerForConnection (UnityEngine.Networking.NetworkConnection conn, UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Networking.PlayerController newPlayerController) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1025)
UnityEngine.Networking.NetworkServer.InternalAddPlayerForConnection (UnityEngine.Networking.NetworkConnection conn, UnityEngine.GameObject playerGameObject, Int16 playerControllerId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:970)
UnityEngine.Networking.NetworkServer.AddPlayerForConnection (UnityEngine.Networking.NetworkConnection conn, UnityEngine.GameObject player, Int16 playerControllerId) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:934)
MyNetworkManager.OnServerAddPlayer (UnityEngine.Networking.NetworkConnection conn, Int16 playerControllerId) (at Assets/Scripts/MyNetworkManager.cs:324)
MyNetworkManager.SpawnChars () (at Assets/Scripts/MyNetworkManager.cs:311)
MyNetworkManager.waitForScene () (at Assets/Scripts/MyNetworkManager.cs:297)
MyNetworkBehaviour.FixedUpdate () (at Assets/Scripts/MyNetworkBehaviour.cs:17)
My Code
public override void OnServerAddPlayer(NetworkConnection conn,short playerControllerId){
ClientInfo info=clientInfos[conn.connectionId];
Transform curSpawner=spawners.FindChild(info.team.ToString());
GameObject plyr=(GameObject)Instantiate(Resources.Load(“Char”+info.charId.ToString()),
curSpawner.position+Vector3.ClampMagnitude(MyUtility.randomV3xz(0,100)/100f,2),
curSpawner.rotation);
plyr.GetComponent().team=info.team;
plyr.GetComponent().team=info.team;
plyr.GetComponent().myName=clientInfos[conn.connectionId].name;
NetworkServer.AddPlayerForConnection(conn,plyr,playerControllerId); //this is line 324
}
I think that’s all for now, thanks. I’m really hoping for a fast reply since I got a deadline.