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 legitplayer09 · Oct 04, 2016 at 03:02 AM · c#networkingmultiplayernetworksynchronization

How to call [Command] on Client in UNet

I'm working on a Unity 2D multiplayer game using UNet. My problem is that the Client cant send the [Command] to the server. Im debugging on UnityEditor and a built apk for my android phone.

First I used UnityEditor as Host and the phone as Client, the Debug.Log(SkinName) APPEARS on the console.

Then I used UnityEditor as the Client and the phone as Host, the Debug.Log(SkinName) DOES NOT APPEAR.

I tried to use [ClientRpc] instead of [Client] but it just made it worse, both client and host wont sync.

I've visited other threads/forums and other UNet tutorials to look for solutions but this is what I came up with.

Note: On the other threads that I visited, people mostly suggest that Local Player Authority is unchecked and that is what causing the problem but in this case it is CHECKED.

Code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 using Spine;
 using Spine.Unity;
 using Spine.Unity.Modules;
 
 class SetupLocalPLayer : NetworkBehaviour {
 [SyncVar]
 public string SkinName;
 
 public string[] CharNames;
 public string[] SlotNames;
 public string[] AttachmentSuffix;
 
 void Start (){
     TransmitSkins ();
     SyncSkin ();
     if (isLocalPlayer) {
         var skeletonrenderer = GetComponent<SkeletonRenderer>();
         for(int z=0;z<SlotNames.Length;z++){
             skeletonrenderer.skeleton.SetAttachment(SlotNames[z],GameController.control.skinName+AttachmentSuffix[z]);
         }
         GetComponent<PlayerManager> ().enabled = true;
         GetComponent<FollowCam> ().enabled = true;
     }
 }
 void Update () {
 
 }
 
 void SyncSkin(){
     if (!isLocalPlayer) {
         var skeletonrenderer = GetComponent<SkeletonRenderer>();
         for(int z=0;z<SlotNames.Length;z++){
             skeletonrenderer.skeleton.SetAttachment(SlotNames[z],SkinName+AttachmentSuffix[z]);
         }
     }
 }
 
 [Command]
 void CmdSetSkin(){
     SkinName = GameController.control.skinName;
     Debug.Log (SkinName);
 }
 
 [Client]
 void TransmitSkins(){
     if (isLocalPlayer) {
         CmdSetSkin ();
     }
 }
 }
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
0

Answer by pseudowok · Oct 20, 2016 at 03:23 PM

It looks to me like you are sending the Debug.Log as a command to the server, so it wouldn't run on the client. If you wanted it to run on the client you would have to do something like:

 [Command]
 void CmdSetSkin(){
 SkinName = GameController.control.skinName;
 RpcSkinName(SkinName);
 }
 
 [ClientRpc]
 void RpcSkinName(String skinName){
 Debug.Log(skinName);
 }
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

Multiplayer desynchronize when grabbing an object by code. 0 Answers

UNET Health isn't syncing 1 Answer

UNET : SyncVar value not updating, hooks firing 1 Answer

How To Deal With Lingering Prefabs in Multiplayer Scene ? 0 Answers

How to synchronize GameObjects 2 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