- Home /
Play Animation After Destroy Gameobject
Can i play animation after destroy my gameobject?
So i set transition for my animation into bool. While gameobject destroy that bool set true.
But my animation cant play.
Answer by SahanD · May 13, 2019 at 05:25 AM
please describe the question more. as i understand you are going to play an animation assigned object, and the object is destroying. so you can't play a animation after selected game object is destroyed. because game object didn't exists. 1. Try to delay the destroy( once you want a destroy the object first animate and then destroy.) 2. Try to control animator using separate game object Animation Manager.
Answer by ernestofranco · Aug 08, 2019 at 06:43 AM
@fernandaputra45 Not sure if you still use this. But I think you should do it the other way around. Play the animation and then destroy the Object. If you destroy the object there won't be any Object to play the animation on, right?
For me this did the trick:
//Create the method that plays the animation, waits, and destroys the object.
IEnumerator DestroyTimer()
{
animator.Play("youranimationname");
yield return new WaitForSeconds(1.2f);
Destroy(gameObject);
}
Add the function on your collision or where you want the animation to be played and destroyed.
StartCoroutine(DestroyTimer());
That should do the trick
Also you can simplify with ;
animator.Play("youranimationname");
Destroy (gameObject, animator.GetCurrentAnimatorStateInfo(0).length);
Answer by unity_JIObz70PulkSVw · Apr 09, 2021 at 03:30 PM
animator.Play("youranimationname"); Destroy (gameObject, animator.GetCurrentAnimatorStateInfo(0).length);
This solution is simpler thanks
Answer by joeyzhao2018 · Nov 28, 2021 at 02:19 AM
I don't know if this sounds like an overkill, but you can have a prefab dedicated to play the animation. And the original object just instantiate the prefab and instantly destroy itself.
Your answer
Follow this Question
Related Questions
the animation walk but he still in the same place and rotate left and right on this white circle 0 Answers
How can I change my AnimatorState instantly? 1 Answer
Animator override controller fails to play sprite animation 1 Answer
Is there a way to change the WrapMode of all Animations in a Mecanim Animator? 1 Answer
Animation Running Game 0 Answers