Hi! I am trying to make my unet running over a self-hosted server, where i can change the max connections to 50 players. But i dont know where to start to make it on my own server. It works over the Unity Servers! I already have a host where i can run the server on Can anyone help me with this? Thankyou!
You don't need anything special. Add the code to start a server in your game by using NetworkServer.Listen() or NetworkManager and then just run the game on your server machine. clients should be able to connect using the machine's public IP and port you specified.
I got it, but it laggs so hard! it is really jittery, it jumps from left to right... instead of smooth i also need a bit help with instantiating over network: I have a missile, that i want to be fired from a client, but everytime i press the keys (C and LEFT CLICK) it comes up with: Code (csharp): Network configuration mismatch detected. The number of networked scripts on the client does not match the number of networked scripts on the server. This could be caused by lazy loading of scripts on the client. This warning can be disabled by the checkbox in NetworkManager Script CRC Check. UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate() Did not find target for sync message for 10 UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate() The 10 keeps counting up. both of my objects identity are set to LocalPlayer Code: Code (csharp): using UnityEngine; using System.Collections; using UnityEngine.Networking; using System; public class MissileLauncher : NetworkBehaviour { [SyncVar] public GameObject missile; public GameObject target; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetButtonDown("Fire1") && Input.GetKey(KeyCode.C)) { if (target == null) { Debug.Log("Cannot find target"); } else { //Network.Instantiate(missile, transform.position, transform.rotation,0); CmdSpawnItem(transform.position, transform.rotation); } } } [Command] void CmdSpawnItem(Vector3 pos, Quaternion rot) { GameObject go = (GameObject)Instantiate(missile,pos, rot); NetworkServer.Spawn(go); } } Screens: ^This one has to be instantiated And he is registred in the network manager, on the local AND the dedicated one
Why are you giving the missle Local Player Authority? That would be the first question I would address. It doesn't point to the error you're getting though.
I gave it Local Player Authority because it keeps giving me an warning with something about trying to instantiate over the network without authority, when i Use Network.SpawnWithClientAuthority(go, connectionToClient); it doesnt work either...
I think that i found the problem with the object instantiating: My server literally only has Network Manager and Network Manager HUD, but nothing to handle the incoming stuff, how would i do that ? My server is basicly a new scene with network manager and a hud, thats all, it accepts connections (ofcourse) but it doesnt handle anything, Can anyone help me with that ? How would i be able to send a CMD from the client to the server and instantiate, in this case, a missile...
You should probably look into the Unity tutorials that show how to make use of Commands and Remote Procedure Calls.
Yeah! I tried: Running SpawnItem() from the client to the server, and at the serverside instantiate the object, but i forgot to add at the server [RPC] haha !
So what i did: This is the client part: Code (csharp): [Command] void CmdSpawnItem(Vector3 pos, Quaternion rot) { GetComponent<CheckSets>().RpcSpawnItem(missile, pos, rot); } and this is the server (CheckSets.cs): Code (csharp): [ClientRpc] public void RpcSpawnItem(GameObject missile, Vector3 pos, Quaternion rot) { GameObject go = (GameObject)Instantiate(missile, pos, rot); NetworkServer.Spawn(go); } its not giving any errors/warnings but it also does not instantiate the object
You've got this a little bit switched around. Your client would call the [Command] method CmdSpawnItem(), which is then, through the magic of UNET, executed on the servers instance of the script/object. So that's the method where you would want to call NetworkServer.Spawn() NetworkServer.Spawn takes care of telling all the clients to instantiate the thing. From then on it's up to you how that new object is handled by the network, if at all.