• RuntimesUnity
  • How to increase FPS (optimization)?

Coin rotation animation. 40 coin pictures to create a full rotation effect.
All coin pictures are in one cell and switch after a certain period of time.

There are no grids or any other changes - just switching pictures.

It has been noticed that about 10 such coins in the camera’s field of view reduce FPS by 10 (everything is very approximate).

If, in addition to coins, there are other animations, then the decrease in FPS may be more significant. Of course, every animation, sprite, or something reduces FPS.
But still, such a decrease in FPS for 10 coins seems strange.

Is there a way to optimize? Reducing the number of pictures, reducing their size, changing the type of animation, etc.?

Do I need to forcefully disable the spine script (so it stop and hide animation) when an object leaves the camera's visibility range?

Related Discussions
...

To optimize the performance of your coin rotation animation and increase FPS, you can consider several strategies:

  1. Reduce the Number of Images: Instead of using 40 images for a full rotation, try reducing the number of images. You can achieve a similar visual effect with fewer images by carefully selecting key frames.

  2. Reduce Image Size: Smaller images consume less memory and processing power. Ensure that your images are as small as possible while still maintaining visual quality.

  3. Texture Atlas: Use a texture atlas to combine all your coin images into a single texture. This reduces the number of texture binds and can significantly improve performance. More information on texture atlases can be found here.

  4. Batch Rendering: Ensure that your rendering process is optimized for batch rendering. This means minimizing draw calls by grouping similar objects together.

  5. Disable Off-Screen Animations: Yes, you should disable the Spine script or any other animation when the object leaves the camera's visibility range. This can be done by checking the visibility of the object and stopping the animation if it is not visible.

  6. Optimize Animation Updates: You can reduce the frequency of animation updates. For example, update the animation every other frame instead of every frame. This can be done by skipping some update calls in the Update and LateUpdate methods.

  7. Use Static Images: For coins that are not actively animating, consider using static images instead of continuously updating animations. This can be particularly useful if the coins are not the main focus of the scene.

  8. Profile and Identify Bottlenecks: Use profiling tools to identify the exact cause of the performance drop. This will help you focus your optimization efforts on the most impactful areas.

Here is an example of how you might disable animations for off-screen objects in Unity:

void Update() {
    if (IsVisibleFrom(Camera.main)) {
        // Enable animation
        skeletonAnimation.enabled = true;
    } else {
        // Disable animation
        skeletonAnimation.enabled = false;
    }
}

bool IsVisibleFrom(Camera camera) {
    var planes = GeometryUtility.CalculateFrustumPlanes(camera);
    return GeometryUtility.TestPlanesAABB(planes, GetComponent<Renderer>().bounds);
}

By implementing these strategies, you should be able to improve the FPS and overall performance of your animations.