Hello,
i’m trying to use Playable to manage my enemy animation, I works but when I quit the game I have a lot of this warning :
Assets/Scripts/Enemy/EnemyAnimator.cs(34): PlayableGraph was not destroyed.
The idea is to have 4 animation clips for four different directions of a walking cycle.
Being able to switch the animation clip depending on the direction of the enemy on update.
Also being able to pause all the animations when the game is paused and resume them when returning to the game.
I have a MonoBehavior to manage this, the code is pretty simple.
I wanted to know I make a good usage of the Playables (certainly not) and how I can achieve this whithout the need of manually defining an animator for each of my different enemies. Thanks !
public class EnemyAnimator : MonoBehaviour
{
private Animator m_animator;
private Enemy m_enemy;
private PlayableGraph m_playableGraph;
private int m_direction = -1;
private AnimationClip[] m_animations;
public AnimationClip east;
public AnimationClip west;
public AnimationClip north;
public AnimationClip south;
private void Awake()
{
m_animations = new AnimationClip[4] { east, north, west, south };
m_animator = GetComponent<Animator>();
m_enemy = GetComponent<Enemy>();
}
private void Update()
{
if (m_direction != m_enemy.Direction)
{
m_direction = m_enemy.Direction;
if (m_direction != -1)
{
AnimationPlayableUtilities.PlayClip(m_animator, m_animations[m_enemy.Direction], out m_playableGraph);
}
}
if (!GameManager.Instance.game.playing)
{
m_playableGraph.GetRootPlayable(0).Pause();
}
else
{
m_playableGraph.GetRootPlayable(0).Play();
}
}
private void OnApplicationQuit()
{
m_playableGraph.Destroy();
}
private void OnDestroy()
{
m_playableGraph.Destroy();
}
}