1
\$\begingroup\$

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: enter image description here

enter image description here

I made the following changes:

  1. Instead of LeanTween, I used my own code for camera animation
  2. Disabled all UI animations
  3. Disabled analytics solutions
  4. Disabled the camera’s occlusion culling property
  5. 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.

\$\endgroup\$
5
  • \$\begingroup\$ What does your profiler show when this stutter happens? \$\endgroup\$
    – DMGregory
    Oct 20, 2020 at 13:18
  • \$\begingroup\$ Thank you for your reply. Please refer to the more information section. \$\endgroup\$
    – Naresh
    Oct 22, 2020 at 10:00
  • \$\begingroup\$ What does your profiler say after removing lean tween? Don't forget to let us see the graph and headers of the columns too. \$\endgroup\$
    – DMGregory
    Oct 22, 2020 at 12:13
  • \$\begingroup\$ I have added the new images as you requested. The execution time (in milliseconds) was increased by 2% after removing LeanTween and replacing it with my code. \$\endgroup\$
    – Naresh
    Oct 23, 2020 at 7:32
  • \$\begingroup\$ The Mono.JIT taking up most of the time there is the just-in-time compiler, which doesn't come into play for iOS builds since they get compiled ahead of time via IL2CPP. So we'll need profiling information from your actual device to be able to diagnose this further. \$\endgroup\$
    – DMGregory
    Oct 23, 2020 at 12:05

1 Answer 1

0
\$\begingroup\$

LeanTween is not something I use since we can animate the camera without any third-party tool using Unity Timeline. My suggestion is to add a half-second delay to that first animation to solve it. Anyhow, the best approach would be to move to Unity Timeline.

\$\endgroup\$
6
  • \$\begingroup\$ Thank you for your reply. I think the Unity timeline will be overkill for my hyper-casual mobile game. In my game, I only need to animate the camera on a linear path. The camera animation start after 3 seconds of delay. The most confusing part about this issue is that it only happens on the first game launch after installation. \$\endgroup\$
    – Naresh
    Oct 21, 2020 at 11:37
  • \$\begingroup\$ It has to be related to the way the assets are initialised. \$\endgroup\$ Oct 21, 2020 at 15:56
  • \$\begingroup\$ Thank you for your reply. Please refer to the more information section. \$\endgroup\$
    – Naresh
    Oct 22, 2020 at 10:00
  • \$\begingroup\$ I'm afraid that not knowing your code structure that is as far as I can go. \$\endgroup\$ Oct 22, 2020 at 17:02
  • \$\begingroup\$ Please refer to the code structure section. \$\endgroup\$
    – Naresh
    Oct 23, 2020 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .