- Home /
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?
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());
}
}
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();
}
}
This may sound stupid; but why is this one variable specifically "m_animator"? Is this just due to personal preference or some coding convention?
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
Answer by chin13577 · Jan 29, 2017 at 07:43 PM
another way if you want to sync animation without animator