https://docs.unity3d.com/Manual/UnityMultiplayerIntegratingHighLevel.html
I have copy&pasted it, tried ‘creating the room’
then joined the room.
Everything seems to be working fine, at least according to debug messages.
Then, I tried spawning my player via cmd/rpc, by adding a simple line of code into the tutorial-code.
public void OnConnected(NetworkMessage msg)
{
Debug.Log("Connected!");
// below added by me
Debug.Log(NetworkServer.active);
FindObjectOfType<SpawnManager>().CmdSpawn(playerPrefab);
}
public class SpawnManager : NetworkBehaviour {
[ClientRpc]
public void RpcSpawn(GameObject go)
{
GameObject thePlayer = Instantiate(go, Vector3.zero, Quaternion.identity);
NetworkServer.AddPlayerForConnection(connectionToClient, thePlayer, 0);
Debug.Log("Spawned successfully");
}
[Command]
public void CmdSpawn(GameObject go)
{
RpcSpawn(go);
}
Now, the debug of “Networkserver.active” returns that the server is not active, even though i’m connected to it, and i’m inside the match. The spawn function fails, and I get nullpointer exception on line:
FindObjectOfType<SpawnManager>().CmdSpawn(playerPrefab);
because the object is inactive (it has networkidentity)
NullReferenceException: Object reference not set to an instance of an object
HostGame.OnConnected (UnityEngine.Networking.NetworkMessage msg) (at Assets/HostGame.cs:101)
I am not sure what to do, the game was working fine when played via hud with combined host&player, but for this type of game I will need a dedicated server with players connecting to it. Any help would be appreciated.