Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 04, 2016 at 02:45 AM by Kadenaa for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Kadenaa · Aug 04, 2016 at 05:36 AM · networkingrpccommandchatunity multiplayer

[UNet] Command not calling RPC on all Clients?

Heyo everyone,

I am having problems getting messages from the server to all of the clients.

The script is placed on my Player object, which has localPlayerAuthority set to true.

 public class Chat : NetworkBehaviour {
     List<string> chatLog = new List<string>();
     string input = "";
 
     void OnGUI() {
         if(isLocalPlayer) {
             foreach(string message in chatLog)
                 GUILayout.Label(message);

             input = GUILayout.TextField(input);
 
             if(GUILayout.Button("Send")) {
                 CmdSendMessageRequest(input);
                 input = "";
             }
         }
     }
 
     [Command]
     void CmdSendMessageRequest(string message) {
         RpcRecieveMessage(message);
     }
 
     [ClientRpc]
     void RpcRecieveMessage(string message) {
         chatLog.Add(message);
     }
 }

Does the command only call the rpc on one client?

If so, how can I get a reference to all of the clients, and by extension to their gameObjects?

If the RPC should be called on all clients, why isn't it working in this instance?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kadenaa · Aug 04, 2016 at 02:43 AM 0
Share

For those wondering, I here is my fix.

 public class Chat : NetworkBehaviour {
     public Server$$anonymous$$anager manager;
 
     [Command]
     void CmdSend$$anonymous$$essageRequest(string message) {
         foreach(GameObject client in manager.clients)
             client.GetComponent<Chat>().RpcRecieve$$anonymous$$essage(message);
     }
 }

 public class Server$$anonymous$$anager : Network$$anonymous$$anager {
     public List<GameObject> clients = new List<GameObject>();
 
     public override void OnServerAddPlayer(NetworkConnection connection, short playerControllerId) {
         base.OnServerAddPlayer(connection, playerControllerId);
         clients.Add(connection.playerControllers[0].gameObject);
     }
 
     public override void OnServerDisconnect(NetworkConnection connection) {
         clients.Remove(connection.playerControllers[0].gameObject);
         base.OnServerDisconnect(connection);
     }
 
     public override void OnStopServer() {
         base.OnStopServer();
         clients.Clear();
     }
 }

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

SyncListString not changing in a Command 0 Answers

SyncListString not changing properly 0 Answers

CHAT Multiplayer Problem 1 Answer

RPC Broadcast using Unet 1 Answer

Gameobject wont move through a function to a ClientRPC 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges