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 /
  • Help Room /
avatar image
0
Question by RescuerRus · Feb 25, 2016 at 07:27 PM · networkingcommand

CommandAttribute doesn't work properly

Good day, guys. I'm working with UNET system, and cannot figure out why that piece of code doesn't work correctly:

 using UnityEngine;
 using UnityEngine.Networking;
 using CnControls;
 
 public class PlayerControl : NetworkBehaviour
 {
 public GameObject bulletPrefab;
 public GameObject wallPrefab;
 [Command]
     public void CmdShoot()
     {
         Debug.log("Shooting");
     }
 
     [Command]
     public void CmdWall()
     {
         Debug.log("Wall");
     }
 private void Update()
     {
         if (!base.isLocalPlayer) {
             return;
 
         }
 
 
         if (Input.GetKeyDown("W")){
             CmdWall ();
         }
         if (Input.GetKeyDown("S")){
             CmdShoot ();
         }
         }
 }

So the main problem is that CmdShoot and CmdWall are both being triggered serverside while CmdWall isn't triggering clientside. Any help is highly appreciated.

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

1 Reply

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

Answer by Salmjak · Feb 25, 2016 at 08:58 PM

[Command] runs functions on the server using variables from the client (as I've experienced it). [ClientRpc] run functions on the clients using variables from the server (as I've experienced it).

[Command] will only run on the server, not both server and client. To make it run on both server and client you can either:

1) Have a regular function that is also called when the [Command] is called (note that this will then only be run at the specific client in question and not on the other clients).

2) Call a [ClientRpc] within your [Command] to make the server send out the new state of the game to all clients.

Comment
Add comment · Show 4 · 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 RescuerRus · Feb 25, 2016 at 10:09 PM 0
Share

Ok, I got it, but how would you explain that shooting command works on both client and server? I just don't really get it, is there are limits for commands?

avatar image RescuerRus · Feb 25, 2016 at 10:13 PM 0
Share

I only want the server to instantiate the objects. Bullets are being instantiated correctly, however the walls arent instantiated on the client when I'm trying to.

avatar image Salmjak RescuerRus · Feb 25, 2016 at 11:11 PM 0
Share

Well, in your above code you only have Debug.Log() :P So as they are in your above example none of the logs should be shown client-side.

Have you attatched a networkidentity and added the prefab to "registered spawnable objects" for both of them? Have you tried to run the client in editor to see if the objects actually do/don't spawn? NetworkServer.Spawn() is not very good at some things (ex. it can't set a parent).

avatar image RescuerRus Salmjak · Feb 26, 2016 at 12:23 PM 0
Share

Sorry for that confusing moment :p

Yeah, I finally figured out what's been going wrong, the command itself was working just fine, I were taking raycast's position from the server camera. :S

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

65 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

Related Questions

Instantiating over the Network, good way? 1 Answer

Command function called on server 0 Answers

Player Object does not have authority? 1 Answer

Can't Add OnClick.Add.Listener To Multiplayer UI 2 Answers

networking one Command works, and one doesn´t 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