• 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 Crystalline · Dec 02, 2013 at 12:24 PM · networkclientsend

Calling a server function from a client?

Hi!

Lets say I have a function on the player,and it should call another one found on the server only.

Since the server only runs on the client that hosts the game,how do I do that.

(BTW, it doesnt work on the client that has the server either).

So,simple question : How do I call a function on server from a client?

Thank you.

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 KiraSensei · Dec 02, 2013 at 12:44 PM

The function can exist on each player, but can be called only on a server. I'm not sure I understand the problem here. You can make a RPC call from a client to the server only with RPCMode.Server. See the doc HERE

Comment
Add comment · Show 5 · 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 Crystalline · Dec 02, 2013 at 12:47 PM 0
Share

I have tried doing this

networkView.RPC('CheckPoints',RPC$$anonymous$$ode.Server);

But it gives me an error telling me that 'CheckPoints' is not attached to the player .. It should send that to server though..

avatar image KiraSensei · Dec 02, 2013 at 02:04 PM 0
Share

No, because it checks if everyone has the method, not only the server. But the method can be called on the server only if your code allows it to be called only on the server :).

Basically, the first parameter defines a function that must exist everywhere, without checking the second parameter (which is read on runtime only).

avatar image Crystalline · Dec 02, 2013 at 02:08 PM 0
Share

In this case I need to create a 'blank' function everywhere, just so it never gives me that error?

avatar image KiraSensei · Dec 02, 2013 at 02:25 PM 0
Share

No, you need to attach the same script to the server and the clients. But this method will only be called on the server because when you call it with a RPC call, you will always put RPC$$anonymous$$ode.Server as second argument.

avatar image Crystalline · Dec 02, 2013 at 02:49 PM 0
Share

Ok,I get it..

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

RPC Call Mix Up Issues 0 Answers

Get RPC senders ID, or IP? 1 Answer

Network.Instantiate dont instantiate object 0 Answers

Can anyone help me with my network script? 1 Answer

Network RPC - exclude specific client 1 Answer


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