Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Jul 17, 2015 at 10:39 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Dudledok · Jul 15, 2015 at 11:26 AM · c#networkingrpcunity multiplayer

Rpc is received by client but Cmd is not received by server

Below is a fragment of my code where the Rpc and Cmd are called. As you can see I check if the player is the client or the server, and depending on which they are I call either an Rpc or a Cmd passing the same parameter. Debugging this script I can see that the server calls RpcSendRList and the client calls CmdSendRList as desired.

 if(networkController.isServer)
 {
     networkController.RpcResetRppList();
     foreach(KeyValuePair<int, float> entry in resources)
     {
         networkController.RpcAddToRppList(entry.Key, entry.Value);
     }
 }
 else
 {
     networkController.CmdResetRppList();
     foreach(KeyValuePair<int, float> entry in resources)
     {
         networkController.CmdAddToRppList(entry.Key, entry.Value);
     }
 }

Below are the Rpcs being called:

 [Command]
 public void CmdAddToRppList(int _key, float _value)
 {
     opponentResources.Add(_key, _value);
 }
 
 [ClientRpc]
 public void RpcAddToRppList(int _key, float _value)
 {
     opponentResources.Add(_key, _value);
 }

Debugging this second script only the Rpc is actually called on the client and the Cmd is never called on the server (the breakpoint is never hit).

What am I doing wrong with the commands?

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Dudledok · Jul 17, 2015 at 10:26 AM

The problem was that the command was not running on the local player. Maybe there should be a warning for if you are trying to send commands from a player that isn't yours, even though when worded like that it should be obvious. I also changed it so that the NetworkManager automatically spawns the player prefab. Letting that do its own thing is the easiest way for sure.

Comment
Add comment · Share
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
1

Answer by n1gth · Jul 15, 2015 at 11:32 AM

You have to make sure that the Command is happening on the Player object - but you should see a warning for that. It's probably because you're not passing an appropriate type through, you should try with a simple type.

Also, in terms of this pattern, it's worth thinking about who is the server and who is the client. For example, you might be a client, but still running on the server. It might be appropriate depending on your use case for a Cmd to be called whether or not you're on the server, and then the Cmd does an RPC to update all objects running on clients.

Comment
Add comment · Show 8 · Share
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 Dudledok · Jul 15, 2015 at 12:07 PM 0
Share

I have a server (who is also a client) and another client. In the legacy system I would simply do an RPC with mode All so everyone runs the code.

avatar image Dudledok · Jul 15, 2015 at 04:13 PM 0
Share

@n1gth - I updated the question with the latest which functions fully as expected for the the RPCs, but no Commands received. Setup: These functions are on a script which inherits from NetworkBehaviour and is attached to a standalone GameObject in the scene which exists for both the server and client.

avatar image n1gth · Jul 16, 2015 at 08:23 AM 0
Share

Are you running a local client on the server like I mentioned above? In this case it'll always hit the first branch of the if, as isServer will be true. Try taking that if statement out and just make the Cmd call.

avatar image Dudledok · Jul 16, 2015 at 08:31 AM 0
Share

Sorry, maybe I didn't make it clear when I said the client calls CmdSendRList as desired. What I mean is the if statement works fine and the client will get to the Command and won't try to call the RPC (which would result in an error I think?), but it's simply not received by the server.

avatar image n1gth · Jul 16, 2015 at 08:44 AM 0
Share

That code looks wrong, the Command method is badly named.

Show more comments

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiplayer Inventory System with RPCs 0 Answers

SyncListString not changing in a Command 0 Answers

Network how to send data/activate function 1 Answer

ClientRpc not called on Client 1 Answer

ClientRpc method called with default value 1 Answer


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