• 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 moghes · Feb 10, 2014 at 02:46 PM · photonmechanim animation

Sync Mechanim animation with OnPhotonSerializeView in PUN

Hello,

I have touble syncronizing data of Animator component via the callback OnPhotonSerializeView().. I am able to see the transform change and tried the same way with the animator component.

Check the code here:

  void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if (stream.isWriting)
         {         
             stream.SendNext(transform.position);            
             stream.SendNext(transform.rotation);
             
             stream.SendNext(this.m_animator);
         }
         else
         {         
             this.correctPlayerPos = (Vector3)stream.ReceiveNext();
             this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
 
             this.m_animator = (Animator)stream.ReceiveNext();
         }
     }

this code is in the script "Network Character" attached to my third person character.

And it gives this error: Exception: cannot serialize(): UnityEngine.Animator

I comment them (leave position and rotation) only, and the error is gone.

Also I thought of this.m_animator.animation = (Animation)stream.ReceiveNext(); but cant do since (`UnityEngine.Component.animation' cannot be assigned to (it is read only)

Any idea of how to syncronize the animations from the animator component?

Comment
Add comment · Show 3
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 moghes · Feb 11, 2014 at 10:25 AM 0
Share

I tried an another method, got no errors but animation is not updated on all clients.

 void OnPhotonSerializeView(PhotonStream stream, Photon$$anonymous$$essageInfo info)
         {
             if (stream.isWriting)
             {         
                 stream.SendNext(transform.position);            
                 stream.SendNext(transform.rotation);
                 stream.SendNext(m_animator.GetBool("Idle"));
                 stream.SendNext(m_animator.GetBool("Run"));
             }
             else
             {         
                 this.correctPlayerPos = (Vector3)stream.ReceiveNext();
                 this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
                 this.m_animator.SetBool("Idle" , (bool)stream.ReceiveNext());
                 this.m_animator.SetBool("Run" , (bool)stream.ReceiveNext());
             }
         }
avatar image moghes · Feb 11, 2014 at 02:11 PM 0
Share

Also tried:

 void FixedUpdate()
     {
         m_animator.SetBool("Run" , runBool);
         m_animator.SetBool("Idle" , idleBool);
     }
     
     void OnPhotonSerializeView(PhotonStream stream, Photon$$anonymous$$essageInfo info)
     {
         if (stream.isWriting)
         {         
             stream.SendNext(transform.position);            
             stream.SendNext(transform.rotation);
             stream.SendNext(runBool);
             stream.SendNext(idleBool);
         }
         else
         {         
             this.correctPlayerPos = (Vector3)stream.ReceiveNext();
             this.correctPlayerRot = (Quaternion)stream.ReceiveNext();            
             idleBool = (bool)stream.ReceiveNext();
             runBool = (bool)stream.ReceiveNext();
         }
     }
avatar image aristaios · Jul 28, 2014 at 05:07 PM 0
Share

This may sound stupid; but why is this one variable specifically "m_animator"? Is this just due to personal preference or some coding convention?

2 Replies

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

Answer by moghes · Feb 28, 2014 at 10:21 AM

Friends I got help from the photon forum, here's the post link: http://forum.exitgames.com/viewtopic.php?f=17&t=4241

and thanks to Razor.

Here's the link he suggests, which solved my issue: http://www.youtube.com/watch?v=4AZADiKD2sE

Comment
Add comment · 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
0

Answer by chin13577 · Jan 29, 2017 at 07:43 PM

another way if you want to sync animation without animator

Photon Play Animation

Comment
Add comment · 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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 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

Related Questions

Help Learning Photon Networking with C# 1 Answer

Is it possible to play animation from a new x axis position? 0 Answers

Find closest player and walk to that one? (PUN) 1 Answer

Default Mecanim Rig 0 Answers

Mecanim altering character posture 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges