Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

    anloko123

    Joined:
    Dec 23, 2015
    Posts:
    64
    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;
    7.  
    8. public class HSNetworkManager : NetworkManager {
    9.     [SerializeField]private string ipAdress;
    10.     [SerializeField] private TMPro.TMP_InputField ipInputField;
    11.  
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.      
    16.     }
    17.  
    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();
    36.  
    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

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,846
    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

    anloko123

    Joined:
    Dec 23, 2015
    Posts:
    64
    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.