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 DoctorMoney · Feb 06, 2017 at 06:42 PM · networkingmultiplayerrpcclient-server

Rpc Can't be called on client - Problem with client, works on server

I'm making an rts and I'm trying to make it so when the builder goes to a structure and hits a trigger then the building spawns on the server. It works just fine on the host and the client receives it fine but when a client tries to build something, I get RpcCompleteStructure can't be called on Client.

OnTriggerEnter call this (structure being something in a local arraylist):

     [ClientRpc]
     private void RpcCompleteStructure(GameObject structure)
     {
 
         if (!isLocalPlayer)
         {
             return;
         }
 
         GameObject completedStructure = Instantiate(structure, structure.transform;
         Destroy(structure); //spawns built structure and destroys construction site placeholder
         NetworkServer.Spawn(completedStructure);
         
         completedStructure .GetComponent<StructureScript>().CompleteBuild(); //completes structure, sets "built" variables
 
     }


StructureScript CompleteBuild:

     public void CompleteBuild()
     {
         GetComponent<UnityEngine.AI.NavMeshObstacle>().enabled = true;
         built = true;
         Destroy(gameObject.transform.GetChild(0).gameObject);
         Destroy(gameObject.transform.GetChild(1).gameObject);
     }




I'm new to multiplayer and would appreciate any help with it. Thank you

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 DoctorMoney · Feb 06, 2017 at 06:45 PM 0
Share

I'd actually prefer to have no placeholder structure for when it's spawned but other answers say that the player should call everything

1 Reply

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

Answer by fuz · Feb 07, 2017 at 01:51 AM

As you said, ClientRpc can only be call on server side, that's why it doesn't work when the client triggers it. Take a look at the documentation: https://docs.unity3d.com/Manual/UNetActions.html

Clients communicate with the server via Commands. The server communicates with the client via RPCs.

One workaround could be to have a Command (client to server) that calls the Rpc (server to client) you need.

Something like:

 if(hasAuthority){
     RpcTest(); //only server executes this part
     }else{
         CmdCallRpcTest(); //client tells the server to execute the Rpc
     }


This could be your command

 [Command]
 void CmdCallRpcTest()
 {
 //Commands can only be sent from YOUR player object
     RpcTest();
 }



Comment
Add comment · Show 1 · 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 DoctorMoney · Feb 10, 2017 at 06:35 AM 0
Share

I figured it out on my own eventually and never though to check this question again, I basically did what you did. ClientRPC and Command are tricky to wrap your head around at first. Thanks for your help!

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

108 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

Related Questions

Unity networking tutorial? 6 Answers

How do you Change Color or any variable of non-player object on both client and server in uNet 0 Answers

Unity Multiplayer (Mirror) - Problem in syncing game object's variables across all clients. [Trying to send command for object without authority] 0 Answers

Server controlled Joint in UNET 0 Answers

Using Server to initialize Stuff on the client [UNET] 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