UNET: Network [Command] from non-player object
This screencast video describes this issue best: https://youtu.be/RXEWM_Nc_K8 Unitypackage below.
I'm working on a chat system with **UNET [Command]**s (Client to Server) and [ClientRpc]s (Server to all connected clients). The host can send messages to any other client using a Unet Network [Command]. But only the host can. Clients, however, cannot send [Command] messages, because they cannot send UNET network commands, as they do not have the authority to do that. The game object, which includes the script ("SendTestMsg.cs"), has a NetworkIdentity component with LocalPlayerAuthority selected. And yet Unity displays
Trying to send command for object without authority.
How can I solve that? I have already found descriptions on this topic, e.g.. https://stackoverflow.com/a/37583086, but I don't get through in my particular case. Help would be appreciated. Unitypackage attached. Thanks in advance
Here is SensTestMsg.cs:
// attached to the CommunicationManager - always in scene
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class SendTestMsg : NetworkBehaviour
{
public Text textfield;
public InputField message;
// Executed at this client
public void PushMessageToServer()
{
if (!isClient) return;
string messageToServer = message.text;
print("called from this client: PushMessageToServer()");
CmdInformServer(messageToServer);
}
// Executed at server
[Command]
void CmdInformServer(string msgFromClient)
{
if (!isServer) return;
print("called from the server: CmdInformServer()");
RpcInformClients(msgFromClient);
}
// Executed at all clients
[ClientRpc]
void RpcInformClients(string msgFromServer)
{
if (!isClient) return;
print("called from all clients: RpcInformClients");
textfield.text = msgFromServer + "\n" + textfield.text;
}
}
Your answer
Follow this Question
Related Questions
Question to RPC and Command (Unet) 0 Answers
iOS Networking 1 Answer
How to command dedicated server 1 Answer
Unity Network Manager or FullRPC 0 Answers
[Command] Not being called at all 0 Answers