Unity Photon: animation syncing

Okay, so I thought this would be really easy to do but (sadly) it’s not. I’ve got a script that takes horizontal and vertical input, and then gets an animator to control a blend tree using those values. And it does work, but when I try to sync up the script over Unity Photon, none of the animations play. I’ve set the script to disable if PhotonView.isMine is false, but I still can’t see other players being animated. Can someone help? Here is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerblend : Photon.MonoBehaviour {

private Animator anim;

// Use this for initialization
void Start ()
{
    anim = GetComponent<Animator>();
}

// Update is called once per frame
void Update ()
{
    if (anim == null)
    {
        Debug.LogError("Animator not present in" + transform.name);
    }

    float x = Input.GetAxis("Horizontal");
    float y = Input.GetAxis("Vertical");

    Move(x,y);
}

private void Move(float x, float y)
{
    anim.SetFloat("VelX", x);
    anim.SetFloat("VelY", y);
}

}

I have also added a Photon Animator View to the character, but to no avail. Thanks in advance for your help!

Hi,

if you want to synchronize the input you make, you have to add a custom OnPhotonSerializeView solution, for example:

public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
    if (stream.isWriting)
    {
        stream.SendNext(x);
        stream.SendNext(y);
    }
    else if (stream.isWriting)
    {
        x = (float)stream.ReceiveNext();
        y = (float)stream.ReceiveNext();

        // Do something with those values (can also happen in the Update function)
    }
}

Before handling input, you should add a PhotonView.isMine condition to avoid input by other clients, that are not the owner of the object. In your Update function you can for example add if (!photonView.isMine) { return; } in order to allow only input from the owner of the object.