- Home /
Need help with a performance issue on my animation script
Hi
I just wanted to know if anyone can find the flaw in my animation script. The script is really not very long and not much is going on, but still I lose around 100 FPS when it is active
var movingAnim : boolean = false;
function Update()
{
Idle();
if (Input.GetButtonDown("Forward"))
{
movingAnim = true;
}
if (Input.GetButtonUp("Forward"))
{
movingAnim = false;
}
if (movingAnim)
{
Move();
}
else if (movingAnim == false)
{
MoveToIdle();
}
}
function Idle()
{
animation.Blend("idle8-motion");
animation.Blend("flap");
}
function Move()
{
animation.Blend("8-motion");
animation.Blend("flap");
}
function MoveToIdle()
{
animation.Blend("8-motion",0,0.3);
animation.Blend("idle8-motion");
animation.Blend("flap");
}
I would really appreciate the help
thanks in advance
You shouldn't call stuff on your animation component every frame.
Do you know a way I can call the functions without it being a Update?
Answer by Tim-Michels · Nov 29, 2012 at 12:59 PM
Your script should look something more like this:
function Start()
{
Idle();
}
function Update()
{
if (Input.GetButtonDown("Forward"))
{
Move();
}
if (Input.GetButtonUp("Forward"))
{
MoveToIdle();
}
}
function Idle()
{
animation.Blend("idle8-motion");
animation.Blend("flap");
}
function Move()
{
animation.Blend("8-motion");
animation.Blend("flap");
}
function MoveToIdle()
{
animation.Blend("8-motion",0,0.3);
animation.Blend("idle8-motion");
animation.Blend("flap");
}
You don't even need the variable movingAnim as far as I know, the main idea is you only need to start an animation instead of calling the start of that animation multiple times.
Please let me know if this script works for you.
Cheers
It "works" just as well as my previous attempts, but I just get a giant FPS-drop whenever this specific script is active on my object. I dont know if animation.Blend has a great effect on performance, but so few of them really shouldn't.
I have checked every other possibility for FPS-drop in my scene, but it is only when I dissable this script my FPS rises.
Well then I assume that your framedrop is caused by the animation itsself. Could you check if you play the animation automatically in your scene (without this script) if you also have this framedrop.
What kind of animation is it, is it with a skinned mesh? If so, how many bones and how many vertices are you using?
The animation does not play automatically.
But you are right about the animation playing automatically cause FPS-drop (without the script).
The animation is a simple unity animation, making the object fly around in a 8-motion (like a fly) on the screen, so there is no skin involved.
So it could be that the model itself is too high-poly? I will come come back to you when I have redone the model, thanks.
GREAT!
I did not really change much in the model but somehow a few tweaks here and there and now there is no drop in FPS at all.
Thanks a bunch, you have just become the shining light of my day :)