- Home /
Why does simple animation make my game lag?
In my prototype, I'm trying to script an elevator, (of maybe twenty vertices at most), to go up via animation. While the animation is playing though, the frame rate drops like an anvil in Dragonball Z training gravity. The scene is highly simple, (it's all cubes).
if(elevator)
{
// Makes player imobile and follow elevator.
playerMove = GameObject.FindWithTag ("player").GetComponent<cube_move>();
playerMove.enabled = false;
playerMove.gameObject.transform.parent = platform.transform;
//plays animation
models.animation.Play(step1);
yield return new WaitForSeconds(3.2f);
if(step2 != "none")
{
models.animation.Play(step2);
yield return new WaitForSeconds(2.5f);
}
//Lets player move again.
playerMove.gameObject.transform.parent = null;
playerMove.enabled = true;
That's not the whole code, is it? Are you doing this within an Update function?
Is the frame rate actually changing? What are the numbers you're getting?
Does the frame rate lag happen every time the elevator animates, or only when your character is in it?
It's in a function that's called every time the player enters it.
I think it's changing because everything just gets skippy, I don't know hot to check the framerate.
It's only during the actual animation.
In Game View, there will be a bar at the top of the screen, and on the right hand side, it says "Stats". Click that for the frame rate and other valuable info.
It might be valuable to watch what's happening from both the Scene View and the Game View. If the elevator moves up smoothly when viewed from the Scene View, then it's more likely a camera issue.
It goes from about 140 to 23, (thanks for the tip by the way). So yeah, it's in both scene and game view.
Wow, that is quite a dip. Is the function called every frame that it's in the elevator, or just once at the beginning of the elevator animation?
Answer by pjcarey97 · Aug 31, 2012 at 11:02 PM
The animations were from a Blender file and stored in the root. So the root had like thirty child objects, and the more child objects it had, the lower the frame rate. When I unparent most of them, the animation worked just fine. So do I need to store the animations in nodes and keep them as separate objects or do I have some kind of obscure setting that caused this?
Oh wait, is it because Unity is adding frames for things that aren't even moving.
Answer by moinchdog · Apr 01, 2013 at 09:03 AM
Do you have a collider on any of the submeshes. For some reason Unity lags up when a collider is animated.