- Home /
Animator.Play() in update, Performance??
Just wanting to know if it is bad for performance if you were to call Animator.Play() in Update()?
void Update()
{
Animator.Play(clipname);
}
I can always check to see if the currently playing animation matches the desired animation, but that adds another overhead, which defeats the purpose.
AnimatorStateInfo currentState = anim.GetCurrentAnimatorStateInfo(layer);
if (currentState.IsName(clipName) == false)
{
Animator.Play(clipName);
}
Or am I being stupid?
There is overhead everywhere, especially where strings are involved. Is it even useful to call Play every frame in Update? I don't think I've ever seen that being done.
So my thought is, yes it creates waste (though it may be negligible), and it also seems illogical and reduces readability.
Although checking the state each frame with a string also costs nanoseconds, it seems logical, enhances readability, and improves code structure.
Just a heads up that you can test performance yourself by creating timers, debug statements, stress-tests, and using the profiler.
It gets put inside an if-statement, pretty much like this:
void Update()
{
if(falling)
{
anim.Play("falling");
}
}
This is so much easier to do than to create switches and what not.
Your answer
Follow this Question
Related Questions
What is better: Set a animator variable each frame or use a if to check if need? 2 Answers
Climb animation in Update or FixedUpdate or LateUpdate?, 1 Answer
using coroutines for move objects - performance. 1 Answer
Colliders vs Transform Position for performance 3 Answers
performance impact of destination update (navmeshagent) 0 Answers