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 Shikamaru99 · Apr 17, 2018 at 02:25 PM · networkingmultiplayerserverclient

Why can't the client move a networked object ?

Hello there my future saviors ! I am working on a multiplayer 2D chess game with UNET, but unfortunately got stuck. So, in my game one of the player is the Server as well as the Client at the same time. My idea is to instantiate all the objects, such as the Tiles and Pieces on the Server, and then use NetworkServer.Spawn to propagate the objects on the Clients, so that both of them can see what's going on. However, when it comes to moving the pieces from the Client which is not the Server, the designated object does not move, despite that it recognizes the piece and all, whereas on the other Client-Server moving the same piece works perfectly.

Here is the how I call the functions which create my objects on the Server :

  void Start()
  {
          if (isServer && isLocalPlayer)
           {
             CreateBoard ();
             SetUpPieces ();
            Debug.Log (" SERVER ");
           }
  }


This is the Command function which moves the piece :

     [Command]
         public void CmdmoveBish(int x , int y)
         {
             Debug.Log ("Command the server to move bishop : ");
             bishop.transform.position = new Vector2 (x,y);
         }

I am sure that the command function is executed from both Clients, because I get the message in the console. Btw, I have noticed that when the non-Server-Client tries to move the piece it changes the coordinates of the piece prefab, instead of the object which was instantiated in the game. It sound like there's a simple solution but I've become very confused. Additional information; this is how I instantiate my piece :

 public void SetUpPieces()
     {       
                         bishop = Instantiate (bishop);      // bishop is a GameObject
             bishop.transform.position = new Vector2 (2,0);
             NetworkServer.Spawn (bishop);
             Debug.Log ("bishop is spawned");
     }

I appreciate your help and thank you in advance :)

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 finlay_morrison · Apr 18, 2018 at 12:58 PM

Inside the command function you need to call another function as an rpc call instead of a command, then from that transform the pieces.

And a little explanation of what an rpc call is, they can only be called by the server (on a function with a command modifier, and that code will be called for all connected clients.

Comment
Add comment · Show 3 · 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 Shikamaru99 · Apr 18, 2018 at 06:08 PM 0
Share
 [Command]
     public void CmdmoveBish(int x , int y)
     {
         Debug.Log ("Command the server to move bishop : ");
         RpcActmove (x, y);
     }
 
     [ClientRpc]
     public void RpcActmove(int a, int b)
     {
         SubBishop.transform.position = new Vector2 (a,b);
         Debug.Log ("RPC executed");
     }


I've tried and it does not change anything.

avatar image villevli Shikamaru99 · Apr 18, 2018 at 07:03 PM 0
Share

The object whose command function you are calling must be the client's player object or an object who has client authority. Read the documentation here. If this is the problem, you should see some warning log messages on the client when calling the command function.

avatar image Shikamaru99 villevli · Apr 19, 2018 at 01:03 PM 0
Share

Yes, I understand what you're saying. But my question and problem is, how can both clients move one object that's on the server? It seems like there's no way to spawn an object with client-authority to both clients.

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

116 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

Related Questions

Unity networking tutorial? 6 Answers

Can a person be both a client and a server? (and more) 0 Answers

Unity Multiplayer - OnStartLocalPlayer() called multiple times 0 Answers

Would it be possible for every person to host the server.... And yet no one. 1 Answer

Seperate server - client 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