Hi there !
I'm using the implementation of mecanim with skeletonANIMATION by MagicPanda, and set that up for networking.
So far everything works pretty well but I've got a thrown error by spine on every state enter (though everything looks ok on client side).
The code is the following
using UnityEngine;
using System.Collections;
using Spine.Unity;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;
public class SpineAnimationBehavior : StateMachineBehaviour {
//string name of animation clip
public string animationClip;
//layer to play animation on
public int layer = 0;
//for playing the anim at a different timescale if desired
public float timeScale = 1f;
private float normalizedTime;
public float exitTime = .85f;
public bool loop;
private SkeletonAnimation skeletonAnimation;
private Spine.AnimationState spineAnimationState;
private Spine.TrackEntry trackEntry;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (skeletonAnimation == null)
{
skeletonAnimation = animator.GetComponentInChildren<SkeletonAnimation>();
spineAnimationState = skeletonAnimation.state;
}
skeletonAnimation.skeleton.SetToSetupPose();
trackEntry = spineAnimationState.SetAnimation(layer, animationClip, loop);
// skeletonAnimation.skeleton.SetToSetupPose();
trackEntry.TimeScale = timeScale;
normalizedTime = 0f;
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if(trackEntry!=null){
normalizedTime = trackEntry.TrackTime / trackEntry.TrackEnd; // where are we in current time (on a 1exit time ratio)
}
//if this animation doesn't loop and we reach
if(!loop && normalizedTime >= exitTime)
{
// actually not a bool but an int to check if exit time is reached
CmdSetBoolTrue(animator);
}
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
{
CmdSetBoolFalse(animator);
}
}
[Command]
void CmdSetBoolTrue(Animator anim){
anim.SetInteger ("transition", 1);
RpcSetBoolTrue(anim);
}
[ClientRpc]
void RpcSetBoolTrue(Animator anim){
anim.SetInteger("transition",1);
}
[Command]
void CmdSetBoolFalse(Animator anim){
anim.SetInteger("transition",0);
RpcSetBoolFalse(anim);
}
[ClientRpc]
void RpcSetBoolFalse(Animator anim){
anim.SetInteger("transition",0);
}
}
The error is thrown OnStateEnter and return "ArgumentException: Animation not found:
Parameter name: animationName" on AnimationState class here :
public TrackEntry SetAnimation (int trackIndex, String animationName, bool loop) {
Animation animation = data.skeletonData.FindAnimation(animationName);
if (animation == null) throw new ArgumentException("Animation not found: " + animationName, "animationName"); //This Line !
return SetAnimation(trackIndex, animation, loop);
}
The animations names are well set, well spelled and do trigger, I don't know why I get this error, any idea ? :party: