- Home /
Photon Stream animation
Hi, I'm trying to play a legacy animation (not using an animator) so that it is visible by the other player. I know how to send it, but how would i receieve it? Thanks in advance for any help.
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
// This is OUR player. We need to send our actual position to the network.
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
if(anim.animation.IsPlaying("Swing"))
stream.SendNext(anim.animation.Play("Swing"));
}
else {
// This is someone else's player
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
//anim.animation.IsPlaying("Swing") = (bool)stream.ReceiveNext(); <---Doesn't work :( how do i receive it?
}
}
Why not just send the name of the animation as a string, then on receive check if that animation is playing (if not, crossfade to it, else do nothing)? I'm fairly sure you can only send ints, floats, booleans, strings, Vectors and quaternions through a serialize view (why would you send an animation when the object should already have that animation stored on it?)
Thanks, but thats the problem, i can't check to see if another players animation is playing. I'm trying to view the other players animation from the camera this script is stored on.
Why not just use RPC calls? Whenever you need remote players to play the swing animation just tell them by using RPC calls.
How, if I cant read which player sent it and who needs to see it? syntax would be great.
Yes, syntax would be great. I keep running into lack of documentation issues with PUN. It seems really simple and efficient though, so I wish I could figure this stuff out.
As for using RPCs, I'm pretty sure that's not what should be used for walking/running animation syncing.
Answer by Khyrid · Feb 01, 2015 at 09:57 AM
I had the same issue trying to get PUN to sync legacy animation. This is what I did that worked for me:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
//This is our player, sent pos to network
stream.SendNext (transform.position);
stream.SendNext (transform.rotation);
if(anim.animation.IsPlaying("walk")){stream.SendNext(useThisMove = 1);}else{stream.SendNext(useThisMove = -1);}
}
else{ //elses player, recive their pos
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
useThisMove = (int)stream.ReceiveNext(); //This is how I received the data, I just used an int.
}
}
Then I added this in the update:
if(useThisMove == 1){anim.animation.Play("walk");}else{if(useThisMove == -1){anim.animation.Play("idle");}} //else won't work.
I used this in the update to change the animation of anyone who had the "useThisMove" var changed. I also needed to make sure I had well written animation code or the animation wouldn't stop. I'm sure my code is messy, but it works.
Your answer
Follow this Question
Related Questions
Unity Photon: animation syncing 1 Answer
how to synchronise an animation which is in a second animation layers, over the network with Photon? 0 Answers
How do you sync animations in Photon? 0 Answers
Photon Syncing Animations 2 Answers
Issues on Syncing the animation component on Photon Network 0 Answers