Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by BigTuna89 · Mar 16, 2012 at 04:26 AM · parentrpcnetworkview

Parenting and RPC functions

I have just discovered the power of unity, however the network aspect is still making me scratch my head. I am trying to parent a weapon(equipment) to another invisible gameobject on the players hand(EquipmentSlots).

It works well on my client. However, the other players cannot see the weapon attach to my hand. I am still trying to do more research on RPC function calls, but I believe I am doing this somewhat correct.

In the network view of the object I set the state synchronization to off as told by numerous tutorials.

If anyone could please help to explain to me how to "update" the data of the object(i.e. the parent change and position change) over the network, it would be greatly appreciated!

 if(equipment[0])
 {
    slot = 0;
    networkView.RPC("equipGun", RPCMode.AllBuffered, slot);
 }
 
 [RPC]
 public void equipGun(int slot)  
 {
    if(networkView.isMine)
    {
       equipment[slot].transform.parent = EquipmentSlots[slot];
         
       equipment[slot].transform.position = new Vector3(EquipmentSlots[slot].position.x,
                                            EquipmentSlots[slot].position.y,
                                            EquipmentSlots[slot].position.z);
         
       equipment[slot].transform.rotation = new Quaternion(EquipmentSlots[slot].rotation.x,
                                                  EquipmentSlots[slot].rotation.y, 
                                                 EquipmentSlots[slot].rotation.z,
                                                 EquipmentSlots[slot].rotation.w);
       equipment[slot].collider.enabled = false;
 }        
 }
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 asafsitner · Mar 17, 2012 at 11:17 AM 0
Share

What is the purpose of if(networkView.is$$anonymous$$ine) ?

The RPC will get to the networkView of the same networkViewID that sent the message, meaning it will only be picked up by your clones on the other players's machines. That if statement is going to return true only for each player's local avatar so they never update the data for your clone.

1 Reply

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

Answer by Dreamside · Mar 17, 2012 at 12:11 PM

What asafsitner said is right. In rpc function you check that if that gameobject is owned by you then equip the item.

Suppose that there are two players in game named A and B. Lets say you
are A. When you call an Rpc it reaches player B. Player B looks that
if it is the owner of object or not via networkView.isMine. But objects' owner is player A so this if statement returns false.

I think you should call rpc with mode RPCMode.others and in body of rpc function don't control for owner information.Because of calling with mode "others" you also should equip gun with a local function.

As a pseudo code i thought something like this:

 void EquipGun()
 {
  // Equip gun codes (will work only locally
  // Call RPC function for tell peers to equip gun
 }
 
 [RPC]
 void RemoteEquipGun()
 {
   //equip gun
 }
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 BigTuna89 · Mar 17, 2012 at 11:01 PM 0
Share

That makes a whole lot more sense. This has been wracking in my brain for 2 days now. Just with that little tip, I think I am going to now be able to make dramatic leaps in my game progress.

Thanks man!!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Passing variables back and forth in client server environment using RPC 1 Answer

RPC calls and animation problems 1 Answer

Network Views from separate scenes causing conflicting IDs? 1 Answer

Send RPC to owning NetworkPlayer of networkView 1 Answer

Couldn't Invoke RPC Function ! 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