Code (CSharp): using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine.Networking; using System; public class Player : NetworkBehaviour { public SyncListString chatHistory = new SyncListString(); string currentMessage = ""; public void OnGUI() { GUILayout.BeginHorizontal (GUILayout.Width (250)); currentMessage = GUILayout.TextField (currentMessage); if (GUILayout.Button ("Send")) { if (!string.IsNullOrEmpty (currentMessage.Trim ())) { Debug.Log ("command sent"); CmdChatMessage (currentMessage); currentMessage = string.Empty; } } GUILayout.EndHorizontal (); foreach (string msg in chatHistory) { GUILayout.Label (msg); } } [Command] public void CmdChatMessage(string msg){ chatHistory.Add (msg); } } This seems to work on the host's side, but not on the client's side, by which I mean the host can send the command, chatHistory is updated on both sides though. The client Player is not able to send the command, when I run this on the client I do get the "command sent" message.
Note that only game objects that have Local Player Authority can send Commands to the server. Is this game object set as local player authorative?
Yep. Also I don't know if it's relevant but this object is an actual Player, from my network manager :
I am not that familiar with SyncLists, but they seem to have a Callback delegate. You could try to use void Start(){ chatHistory.Callback = DoWhatever; } Where DoWhatever is a method that will ensure the changed list is drawn on screen. I am not sure this is necessary though since you draw your sync list in the OnGUI. At the least, with this method you can check if the value is actually changed on clients. Hope this helps!
Rather than doing this I can Debug.Log the length of the chatHistory list in the Player's update function. I can confirm that chatHistory is not changed when the client calls the command.
Now that I think of it, this might not work because the OnGUI code is ran for both the client and the host on both instances. You need to isolate the execution so that the input field and the send button are only visible for the local player. Something like this: Code (CSharp): public void OnGUI() { if (isLocalPlayer) { GUILayout.BeginHorizontal(GUILayout.Width(250)); currentMessage = GUILayout.TextField(currentMessage); if (GUILayout.Button("Send")) { if (!string.IsNullOrEmpty(currentMessage.Trim())) { Debug.Log("command sent"); CmdChatMessage(currentMessage); currentMessage = string.Empty; } } GUILayout.EndHorizontal(); } foreach (string msg in chatHistory) { GUILayout.Label(msg); } } However, doing this you might want to arrange stuff differently since it breaks your layout
I thought that might be the case too, tried it, didn't make a difference Thanks for the help and patience, it turned out this was part of the problem, I've fixed it.