Search Unity

Unity Multiplayer Client can't send Commands to a dedicated server without SERVER Player

Discussion in 'Connected Games' started by anloko123, Sep 14, 2018.

  1. anloko123


    Dec 23, 2015
    Hi, so i have a really basic and simple code to start a dedicated server and connect to one of them.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5. using System.Text.RegularExpressions;
    6. using UnityEngine.SceneManagement;
    8. public class HSNetworkManager : NetworkManager {
    9.     [SerializeField]private string ipAdress;
    10.     [SerializeField] private TMPro.TMP_InputField ipInputField;
    13.     // Use this for initialization
    14.     void Start () {
    16.     }
    18.     // Update is called once per frame
    19.     public void PlayClient()
    20.     {
    21.         if(ipAdress == null)
    22.         {
    23.             print("Ip is not correct");
    24.             return;
    25.         }
    26.         print("Connecting...");
    27.         NetworkManager.singleton.networkAddress = ipInputField.text;
    28.         NetworkManager.singleton.networkPort = 7777;
    29.         NetworkManager.singleton.StartClient();
    30.     }
    31.     public void StartDedicatedServer()
    32.     {
    33.         NetworkManager.singleton.networkPort = 7777;
    34.         NetworkManager.singleton.networkAddress = "localhost";
    35.         NetworkManager.singleton.StartServer();
    37.     }
    38. }
    When i connect to a server with PlayClient() it connects to the server but it tells me that i don't have any authority to send a command.

    But when i start server using StartDedicatedServer() with NetworkManager.singleton.StartClient() added. I can send commands as a client and i don't get any errors but clients spawn twice.

    Is there a possibility to handle commands using StartServer() only?(without server player)

    I hope You understand.
  2. Joe-Censored


    Mar 26, 2013
    Well to send a command from a client, the server needs to assign that client authority over the object, or the object must be that client's special Player gameobject. Otherwise the client will get a log message stating it doesn't have authority to send the command.

    You haven't said anything about the object you are using to send the command, so my first guess is trying to call a Command on a client which does not have authority over the object, or is not that client's Player gameobject.
  3. anloko123


    Dec 23, 2015
    The object to send commands is the player(client). In my code i assign client authority to some objects but they still don't respond without the server player. I have an idea how to fix that, i will just spawn the server player as an invisible object and always add one to slots integer. But i don't really want to make it work that way.