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 Heffalus · Mar 18, 2015 at 12:52 PM · c#photonsynchronizationparent-child

Photon synchronization

Im having a hard time synchronizing weapons for my character. I have a GameObject "WeaponAttacher" that holds the position and rotation for the weapon, it is a child of the hand bone. When i equip a weapon i set the weapon gameobjects rotation and position to the attachers and i parent it to the attacher gameobject. I dont get what i need to synchronize for other clients to see.

 WeaponSlot = (GameObject)PhotonNetwork.Instantiate (name, WeaponAttacher.position, WeaponAttacher.rotation, 0);
                 WeaponSlot .GetComponent<DroppedItem> ().item = itemDatabase.getNewItem(id);
                 WeaponSlot .transform.parent = WeaponAttacher;
                 EquippedWeaponSlot = WeaponSlot ;

The EquippedWeaponSlot is just a reference to the currently equipped weapon, as i have 2 slots for weapons.

The weapon is instantiated in the right place, its just not following the movement it should.

This is the syncronization code:

 void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info) {
         
         if (stream.isWriting) {
             stream.SendNext (WeaponAttacher.transform.rotation);
             stream.SendNext (WeaponAttacher.transform.position);
             stream.SendNext (WeaponSlot.transform.position);
             stream.SendNext (WeaponSlot.transform.rotation);
             stream.SendNext (transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").position);
             stream.SendNext (transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").rotation);
         } else {
             WeaponAttacherRecievedRotation = (Quaternion) stream.ReceiveNext();
             WeaponAttacherRecievedPosition = (Vector3) stream.ReceiveNext();
             WeaponSlotRecievedRotation = (Quaternion)stream.ReceiveNext ();
             WeaponSlotRecievedPosition = (Vector3)stream.ReceiveNext();
             handBonePosition = (Vector3) stream.ReceiveNext();
             handBoneRotation = (Quaternion) stream.ReceiveNext();
         }
     }

and this is started as a coroutine from the start method after a check if !photonview.ismine:

 IEnumerator UpdateData () {
         while (true) {
                 WeaponAttacher.transform.rotation = WeaponAttacherRecievedRotation;
                 WeaponAttacher.transform.position = WeaponAttacherRecievedPosition;
                 WeaponSlot.transform.rotation =WeaponSlotRecievedRotation;
                 WeaponSlot.transform.position = WeaponSlotRecievedPosition;
                 transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").position = handBonePosition;
                 transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").rotation = handBoneRotation;
 
 
 
             yield return null;
         }
     }
Comment
Add comment · Show 6
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 siaran · Mar 18, 2015 at 11:31 PM 0
Share

Okay, let's start with narrowing down the problem.

First, do you have a photonView that is observing the script that has your OnSerializeView method?

Two, check if your OnSerializeView method is receiving data correctly (simply send some value and print it when you receive it, check if you get the same value)

Three, check if your UpdateData() method is firing, and also if it is using the correct data. (You can test this basically the same way as in 2, just have some value that you change over the network, then check if it's actually changing in your client).

Four, check when you equip a weapon with the top part of your code if those assignments happen properly on both clients.

Can't think of any other place your problem could be right now, so let's figure out exactly where in the pipeline it appears, then we can find a solution.

avatar image Heffalus · Mar 19, 2015 at 11:42 AM 0
Share

ok thank you, 1, the player has a photonview attached that is observing the script. 2, i sendt a vector3 and printed it upon recieve, it worked. 3, i tried sending a changing value and printing it in the UpdateData, it didnt work, and i get errors:

PhotonView with ID 1001 has no method "InstantiateRanged" that takes 3 argument(s): int32, string, int32. and The observed monobehaviour (player(clone)) of this photonview does not implement OnPhotonSerializeView()!

avatar image siaran · Mar 19, 2015 at 06:33 PM 0
Share

PhotonView with ID 1001 has no method "InstantiateRanged" that takes 3 argument(s): int32, string, int32.


That means you're calling a method InstantiateRanged(int, string, int) somewhere that doesn't exist, most likely because your method is something like InstantiateRanged(int, string), i.e. the number and/or types of arguments don't match.


The observed monobehaviour (player(clone)) of this photonview does not implement OnPhotonSerializeView()!

This error means that you have a photonView somewhere that is observing a script, but that script has no OnSerializeView() method. Which makes observing that script a bit pointless, since no data gets sent or recieved in that case.


Somewhat strange that you didn't get those errors before, though, it seems like you should have. Still, it's a starting point.

avatar image Heffalus · Mar 19, 2015 at 06:38 PM 0
Share

I figured those errors out, the method arguments where wrong and i had put another script by mistake to be observed by the photonview.

avatar image siaran · Mar 20, 2015 at 04:53 PM 0
Share

All right, so now that you have resolved those, do you get a correct updated value in your UpdateData() method?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Mickwa · Mar 21, 2015 at 10:34 PM

Is order in OnPhotonSerializeView of stream.SendNext() and stream.ReceiveNext() correct? You send position than rotation:

 stream.SendNext (WeaponSlot.transform.position);
 stream.SendNext (WeaponSlot.transform.rotation);

and You should read in the same order as you sent position than rotation:

 WeaponSlotRecievedPosition = (Vector3)stream.ReceiveNext();
 WeaponSlotRecievedRotation = (Quaternion)stream.ReceiveNext();
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 Heffalus · Mar 22, 2015 at 01:28 PM 0
Share

Dont know how i missed that, looked over the sccript so many times, thank you. It didnt solve my problem tho

avatar image Heffalus · Mar 22, 2015 at 01:38 PM 0
Share

oh my god i just figured it out.. i have another script that disables all character scripts if the photonview is not $$anonymous$$e. So this script was allways disabled.

avatar image DRRosen3 · Jun 11, 2015 at 06:40 PM 0
Share

This isn't true. You deserialize in the same order that you serialize. Not in reverse order.

avatar image Mickwa · Jun 11, 2015 at 09:54 PM 0
Share

@DRRosen3, I updated my comment, thanks for pointing out that it was not valid any more!

avatar image DRRosen3 · Jun 12, 2015 at 01:12 PM 0
Share

@$$anonymous$$ickwa Hmm...I'm fairly new to PUN (less than a year experience) so I wasn't aware that in the past your original post was true. In any case, glad we got it straightened out for future readers!

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

22 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

Related Questions

How can I synchronize Instantiated children of a GameObject over Photon? 1 Answer

Sync game objects across network Photon C# 1 Answer

Snychronize player's name over Photon? 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 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