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 Sebane1 · Sep 04, 2015 at 12:43 AM · c#networkingmultiplayerclient-server

UNET Client Cant Send Server Commands, Host Can.

So as the title suggests, I'm having a problem where commands being sent by the client are not triggered.

The basic functionality I'm trying to get working is that when an enemy is in front of the player and I click, that player will be momentarily stunned. Works fine if I'm host, and both sides perfectly register.

If I'm playing as client, I get to the point where the command "should" be sent, but I notice I get a warning that says "Trying to send command for non-local player". As well, nothing happens on either end. Obviously I must be doing something wrong client side, but have no idea what other way to go about this.

The "problem" code.

             if (Input.GetButtonDown("Fire1")) {
             Ray ray = new Ray(transform.position, transform.forward);
             RaycastHit hit = new RaycastHit();
             Physics.Raycast(ray, out hit, 20f);
             if (hit.transform != null) {
                 if (hit.rigidbody != null) {
                     PlayerController controller = hit.rigidbody.GetComponent<PlayerController>();
                     if (controller != null) {
                         if (!controller.stunned) {
                             // Send the stun command to the server
                             controller.CmdStun();
                         }
                     }
                 }
             }
         }

The method calls

 [Command]
 public void CmdStun() {
     // Report that the stun was sent
     UnityEngine.Debug.Log("Stun Sent");
     RpcStun();
 }

 [ClientRpc]
 public void RpcStun() {
     // Activate the stun timer.
     stunTimer.Start();
     // Track the players original color.
     normalColor = manager.color;
     // Make the players bot look like its shut down.
     manager.InitiateColorChange(Color.black);
     // Other code will check against this before trying to send another stun command.
     stunned = true;
 }

Heres the two scripts in their entirety.

http://pastebin.com/mr4A9ZgH

http://pastebin.com/Qg0AjCCD

Player configuration in unity:

https://gyazo.com/400c5b3a95c1a58f9b6e930b0c3c853b

https://gyazo.com/c17a7317767a00e2150ff34b03a03e8f

https://gyazo.com/322731aefbe69f9567d2b395523b8f2a

Comment
Add comment · Show 4
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 ZefanS · Sep 04, 2015 at 10:00 AM 0
Share

Does your player prefab have the Local Player Authority box checked in the Network Identity? It might be helpful to post some screenshots of the Inspector because I've found problems like this can arise due to those settings even when the script itself is correct.

avatar image Sebane1 · Sep 04, 2015 at 12:43 PM 0
Share

Updated the question, Everything is properly configured as well.

avatar image ZefanS · Sep 07, 2015 at 01:23 AM 0
Share

Looking at everything so far, my first guess would be to try setting Local Player Authority to true on the $$anonymous$$overioCameraRig's Network Identity, since it is the one calling the command. You might also try making ObjectInteractor a Network Behaviour, but I'm not so sure that it's necessary.

I'm also wondering if you might want to put in an isLocalPlayer check into CmdStun() because there's a possibility that it's being called on both the host and the client simultaneously, which could lead to that error you were seeing. Again, I'm not too sure about this without trying it myself.

avatar image Nick_Rizzo · Jul 25, 2017 at 08:31 PM 0
Share

did you ever find a solution to this?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by LeopardX · Dec 02, 2015 at 06:43 PM

Make sure your calling the command in a class on the player object, you cant do it any other way unless you spawn an object with authority.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

UNet | I'm having trouble assigning authority to game objects 0 Answers

Unity networking tutorial? 6 Answers

Qos type ReliableFragmented channel, won't fragment our stream 2 Answers

Only one player for the host but two for the client, 0 Answers

[UNET] Connection between Client and Server dies without message 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