Synchronizing animations over Photon network

Hello,
I have a problem with one animation which is not played each times over the network like my other animations.
All my animations are synchronized exepted the "Fire1"animation which is played one in five.
This is my code, if I miss something :

using UnityEngine;
using System.Collections;

[RequireComponent(typeof (Animator))]

public class NetworkCharacter : Photon.MonoBehaviour {

Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;

Animator anim;

// Use this for initialization
void Start () {
anim = gameObject.GetComponentInChildren<Animator> ();
if (anim == null){
Debug.LogError ("Omg, I forgot to put an Animator component on this Character prefab !");

}

}

// Update is called once per frame
void Update () {
if (photonView.isMine) {
// Do nothing -- the script joueur ...ismoving us

} else {
transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(transform.rotation, realRotation ,0.1f);
}
}

public void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info){
if (stream.isWriting) {
// C'est notre joueur. Nous devons envoyer notre position sur le réseau
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(anim.GetFloat("Speed"));
stream.SendNext(anim.GetFloat("Direction"));
stream.SendNext(anim.GetBool("Walk"));
stream.SendNext(anim.GetBool("Couch"));
stream.SendNext(anim.GetBool("TurnLeft"));
stream.SendNext(anim.GetBool("TurnRight"));
stream.SendNext(anim.GetBool("Fire1"));
stream.SendNext(anim.GetBool("Reload"));
stream.SendNext(anim.GetBool("Jump"));
stream.SendNext(anim.GetBool("JumpDown"));


} else {
//c'est un autre joueur. Nous devons recevoir sa position sur le réseau
//Ceci toutes les mill isecondes et MAJ notre version de ce joueur
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
anim.SetFloat("Speed",(float)stream.ReceiveNext());
anim.SetFloat("Direction",(float)stream.ReceiveNext());
anim.SetBool("Walk",(bool)stream.ReceiveNext());
anim.SetBool("Couch",(bool)stream.ReceiveNext());
anim.SetBool("TurnLeft",(bool)stream.ReceiveNext());
anim.SetBool("TurnRight",(bool)stream.ReceiveNext());
anim.SetBool("Fire1",(bool)stream.ReceiveNext());
anim.SetBool("Reload",(bool)stream.ReceiveNext());
anim.SetBool("Jump",(bool)stream.ReceiveNext());
anim.SetBool("JumpDown",(bool)stream.ReceiveNext());


}
}
}


Thanks in advance for your help!

Comments

  • I don't see an error but I also didn't run your code and can't look at your project. Check the console please.
    I just released PUN 1.50. This includes a component for Mecanim Animations: PhotonAnimatorView. That might be worth checking out.
    Make sure you use PhotonNetwork.Instantiate and that the scripts are active. You can check that in the Editor, too.

    In worst case, Fire1 is a trigger and only valid for a frame. Then the update script might miss it.
  • Hi Tobias,

    I tried to add PhotonAnimatorView, I'm sorry but I'm a Nub and it tell's me "Animator doesn't have any layers setup to Sync".
    Could you explain me how could I do This ?

    Thanks for helping me.
  • I will ask Oliver to help. In this specific case, he is the one who knows the systems in an out.
    He will probably need a bit of time to respond. Please bear with us.
    Thanks.
  • Thank you very much I'll wait his answer.
  • You might have to go into the PhotonAnimatorView script and change the way it locates your Animator. By default it adds an Animator component to the GameObject you put the script on and uses that. Seeing as in your code above you get your Animator from a child, you might have to tell PhotonAnimatorView to do the same. Also tell it not to require an animator on the GameObject you have it on.
  • I'm not sure of what I did but there is some kind of progress with the PhotonAnimatorView but it is not working perfectly, my animation is now played half the time.
  • I have a similar issue with photon.... PhotonAnimatorView but it is not working perfectly, my animation is now played half the time.