• 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
Question by willkzhang · Apr 11, 2013 at 05:34 PM · c#networkingnetworkrpc

RPC and multiplayer networking

I read the manual from the official documentations.

But it only roughly introduces what it is. I have so many questions that i cant find the answers anywhere.

  1. when i call a non-static function "foo" in class A remotely from the client, how does the server know w$$anonymous$$ch instance of A has its foo invoked, if there are many gameobjects have A attached?

  2. if the remotely called function "foo" has other function "foo2" calls inside foo's method body, what happens if that foo2 function is RPC/non-RPC in each case? what if foo is recursive?(that is foo2 is simply foo)

  3. suppose foo2 is not a member function of class A, but rather a function of class B. Is there anyt$$anonymous$$ng special that I should pay attention to?

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Yokimato · Apr 11, 2013 at 05:51 PM

Hopefully I can answer all of these.

  1. The second argument of the Network.RPC function, is the target. So what you put in there is how the server knows who to send it to. (source)

  2. foo2 can't be an RPC function unless you're making another Network.RPC call to it. Once you've received an RPC in a RPC function, you can call any functions you want since it's a wit$$anonymous$$n an instance at that point.

  3. Again, from number 2, once you're in an RPC function...your have an instance so world's your oyster at that point. The another caveat is again calling RPC functions.

Per your comment, I t$$anonymous$$nk what you're having trouble with is understanding the abstraction Unity is doing on your behalf for synchronization in that your A class will have N amount of instances, all of w$$anonymous$$ch have and maintain their own state and not state of each instance of A.

Comment

People who like this

0 Show 2 · 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 willkzhang · Apr 11, 2013 at 05:55 PM 0
Share

i know RPCMode specifies which client/server has to make the function call. but im actually asking which instance of that class calls the function.

avatar image Yokimato · Apr 11, 2013 at 05:58 PM 0
Share

? The one that runs that code...your code should not be setup so that N number of class A is making the same RPC at the same time most likely. The point is to communicate when something happens. Client 0 of Class A takes damage, so Client 0 of Class A sends out the RPC (maybe class A has a TookDamage function that does the RPC call). However, 10 seconds later, Client 4 of Class A now takes damage, so it then calls it's TookDamage method and sends out the RPC.

avatar image

Answer by whydoidoit · Apr 11, 2013 at 05:58 PM

So you call an RPC on a local object with a networkView and it calls the remote objects depending on how you address it - Everyt$$anonymous$$ng, the Server, Others, or a specific NetworkPlayer.

If you continue to recursively call functions then again that will operate on w$$anonymous$$chever component you address the RPC call.

NetworkViews have a unique NetworkViewID that is the same on every computer and is used to address the actual object that will be called. You normally have at least one item in the scene that is allocated a scene NetworkViewID and can be used to communicate with all clients - t$$anonymous$$s is owned by the server. Other objects will be owned by the t$$anonymous$$ng that called AllocateNetworkViewID or instantiated it.

Comment

People who like this

0 Show 0 · 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.

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

12 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

Related Questions

Multiplayer Moving Bullet 1 Answer

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

Networking RPC sends to wrong target 0 Answers

How can i send a Player list to every Client 0 Answers

Acess server stuff by the client 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