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 /
avatar image
0
Question by CiberX15 · Oct 07, 2017 at 11:54 PM · networkingmultiplayernetworkmultiplayer-networkingclient-server

Network command is running on client?

Ok so I am trying to set up the respawn system for a multiplayer first person shooter. My understanding is that commands can only be called on client and only run on server, and similarly clientRPC's can only be called on server and only run on client. I am using the following code:

 [Command]
     public void Cmd_Respawn()
     {
         Health = 100;
         Rpc_Respawn();
     }
 
     [ClientRpc]
     void Rpc_Respawn()
     {
         RespawnCanvas.gameObject.SetActive(false);
         dead = false;
 
         r.constraints = RigidbodyConstraints.FreezeRotation;
         transform.localRotation = Quaternion.identity;
 
         //TODO respawn at a spawn point
         transform.position = new Vector3(0, 2, 0);
 
         if(isLocalPlayer)
         {
             //Update our Position
             Cmd_UpdateServerTransform(transform.localPosition, transform.localRotation.eulerAngles, Head.localRotation.eulerAngles.x);
         }
     }

When the player is dead a UI is visible that lets them click a re spawn button. That button calls Cmd_Respawn() on the local client. When I do I get the error "RPC Function Rpc_Respawn called on client."

I don't understand what I am doing wrong. If Cmd_Respawn() is called on the client then is should run on the server so when Rpc_Respawn is called, it should be being called on the server, sending the instructions to re spawn the player to all clients, including the one that initiated the re spawn, but instead it is is apparently trying to run the entire command on the client?

Why is the Command being run on the client not on the server?

Some additional information: The Player class this code appears in extends from an Entity class, which extends from NetworkBehavior. Not sure if NetworkBehavior doesn't play nice with inheritance?

There is a different Command elsewhere in Player that is responsible for updating the players position via sync vars (I don't use a network transform) and that is working fine. So its not all commands, just this re-spawn command.

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 CiberX15 · Oct 08, 2017 at 05:20 AM 0
Share

Edited because I realized that the entire command is being run on the client, not just the ClientRpc call. In fact, if I create a Respawn() function with the same code but no [Command] attribute, the behavior is exactly the same. For some reason the client is treating the Cmd_Respawn() function like a normal function and not a command...

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by CiberX15 · Oct 08, 2017 at 05:37 AM

I figured it out! (and by I, I mean not me at all but Thammuz90 on redit: https://www.reddit.com/r/Unity3D/comments/3ibx25/unet_commands_running_on_client_instead_of_server/

So apparently it did not like me calling the Cmd_Respawn() function directly. I don't know if its any external class attempting to call the command, or some weird interaction with the UI button calling it. In any case the solution was for the UI button to call Respawn() (a normal public function) on the Player, which in turn called Cmd_Respawn(). Doing it this way caused the Cmd to properly run on server and everything worked as expected.

So now my code looks like this:

 public void Respawn()
     {
         Cmd_Respawn();
     }
 
     [Command]
     public void Cmd_Respawn()
     {
         Health = 100;
         Rpc_Respawn();
     }
 
     [ClientRpc]
     void Rpc_Respawn()
     {
         RespawnCanvas.gameObject.SetActive(false);
         dead = false;
 
         r.constraints = RigidbodyConstraints.FreezeRotation;
         transform.localRotation = Quaternion.identity;
 
         //TODO respawn at a spawn point
         transform.position = new Vector3(0, 2, 0);
 
         if(isLocalPlayer)
         {
             //Update our Position
             Cmd_UpdateServerTransform(transform.localPosition, transform.localRotation.eulerAngles, Head.localRotation.eulerAngles.x);
         }
 
     }

I agree with Thammuz90 that if this is intentionally blocked, there should be an error or warning letting us know that calling a Cmd from an external class will not run the function as a Cmd. Unless this is a bug and it should be running the Cmd when an external class calls it.

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

118 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking solution (PUN or Bolt) 0 Answers

Unity multiplayer solutions: Photon, Unity Networking - what else and in what way is good? 0 Answers

Unity Multiplayer Design. Is it complicated to implement and learn? 1 Answer

Network Game - all players respond to same input 0 Answers

Multiplayer Object spawned by client does not show up on host 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