The camera stutter for a fraction of a second when animating a camera from one position to another position. This issue only happens when the game is launched for the first time after installation. The camera animation is smooth for further game launches.
I am using LeanTween to animate the camera. No data is loaded while the camera is animating.
Environment:
Unity version: 2019.3.03f
Mobile platform: iOS
iOS versions: 12 and above
More information:
The assets are being initialized and loaded on the first screen. I have a module to initialize all the assets before the camera starts panning. I also seeing stutters on the first installation for certain 3D objects animation; these objects are also loaded on the first screen. I don’t know what else to improve with the initialization.
Since we can’t run Unity’s profiler on real devices, I ran the profiler on Unity’s editor and looked at the call stacks at the points where you see the spikes. Below is the screenshot of the call stack of a spike during a specific animation stutter:
I made the following changes:
- Instead of LeanTween, I used my own code for camera animation
- Disabled all UI animations
- Disabled analytics solutions
- Disabled the camera’s occlusion culling property
- Camera animation using Unity Timeline
However, these changes did not affect the stutters.
Also, I am not seeing the stutters in the editor but they are clearly visible on a device. I can’t profile the game on a device using Xcode since it is not using native code.
I ran the same code on a few Android devices and I am not seeing the stutters there.
I would appreciate any suggestions and thoughts on this topic. Thank you.
Code structure:
My game has three screens (A, B, and C). All the mesh files, materials, and game objects present on screens B and C are initialized and set to be active from the start of the game; in other words, everything is loaded on screen A before the animation to screen B begins. Occlusion culling is on for the camera.
The camera stays on screen A for 3 seconds and then animates to screen B. After the user performs a certain action on screen B, the camera animates to screen C.
The stutters happen when the camera is halfway between screens A to B and halfway between screens B to C.