Boost Performance with Animation Instancing in Unity

Updated on Mar 22,2024

Boost Performance with Animation Instancing in Unity

Table of Contents:

  1. Introduction
  2. The Issue of Framerate
  3. Animation Instancing
  4. Downloading and Importing the Asset
  5. Creating the Scene
  6. Applying Animation Instancing to a Single Zombie
  7. Modifying Materials and Adding Animation Instancing Manager
  8. Using the Animation Generator
  9. Building Asset Bundles with Asset Bundle Browser
  10. Applying Animation Instancing to Multiple Zombies
  11. Conclusion

👉 The Issue of Framerate

One of the challenges that developers often face when working with 3D models in Unity is optimizing the performance when displaying a large number of models on screen. While it may be tempting to simply duplicate the models to create a realistic scene, this can lead to significant framerate issues. In this article, we will explore a solution to this problem called animation instancing, which is a technique provided by Unity Technologies.

👉 Animation Instancing

Animation instancing is a feature in Unity that allows developers to efficiently display multiple instances of the same animated model without sacrificing the frame rate. Instead of duplicating the model, animation instancing reuses the animation data and shaders, resulting in improved performance. By utilizing animation instancing, developers can display thousands of models on screen while maintaining a smooth frame rate of at least Sixty.

👉 Downloading and Importing the Asset

To start using animation instancing, you first need to download the animation instancing asset from Unity's GitHub repository. Once downloaded, extract the asset and import it into your Unity project. Make sure to set the main camera's tag to "main camera" for proper functionality.

👉 Creating the Scene

To demonstrate the benefits of animation instancing, we will create a scene with a thousand models. For this demonstration, we will use a zombie model. Import the zombie model into your project and drag it into the scene. Modify the animation controller to make the zombie walk in place on a loop.

👉 Applying Animation Instancing to a Single Zombie

To apply animation instancing to a single zombie, create an empty Game object and group all but one of the zombies under it. This will allow us to easily enable and disable the zombies during the process of applying animation instancing. Set the materials of the zombies to use the animation instancing shader. At this point, the zombie will become invisible, but this is expected behavior.

👉 Modifying Materials and Adding Animation Instancing Manager

Animation instancing requires the use of shaders. Unity's animation instancing asset provides several pre-made shaders that can be used. Set the materials of the zombies to use the provided animation instancing shader. Additionally, add the Animation Instancing Manager to the scene by adding it to the directional light. Finally, add the Animation Instancing script component to the zombie model's game object.

👉 Using the Animation Generator

To generate the animation textures required for animation instancing, navigate to the Animation Generator using the Animation Instancing menu item. Drag the zombie asset into the animation generator and adjust the framerate if needed. Make sure to select the animation you plan to use and click on the generate button. Wait patiently while the script generates the animation textures.

👉 Building Asset Bundles with Asset Bundle Browser

To build the asset bundles required for animation instancing, we will use the Asset Bundle Browser Package. Install the package from the Unity Package Manager and open the Asset Bundle Browser window. In the configure tab, select the animation textures and build the asset bundle for the target platform. Make sure to check the box for copying to streaming assets.

👉 Applying Animation Instancing to Multiple Zombies

Once the asset bundles are built, assign the zombie prototype to all the other zombies' Animation Instancing components. Finally, enable all the zombies and run the scene to see the improved performance of animation instancing. By utilizing animation instancing, the framerate should be acceptable, and the number of batches should be significantly reduced.

👉 Conclusion

Animation instancing is a powerful technique provided by Unity Technologies that allows developers to efficiently display multiple instances of animated models. By utilizing animation instancing, developers can create scenes with thousands of models while maintaining a smooth framerate. This technique is essential for optimizing performance in Unity projects and achieving visually impressive results.

⭐ Highlights

  • Animation instancing is a technique in Unity for efficiently displaying multiple instances of animated models.
  • By reusing animation data and shaders, animation instancing improves performance and reduces framerate issues.
  • Animation instancing can be applied to multiple models in a scene, allowing for the display of thousands of models without sacrificing performance.
  • The animation instancing asset can be downloaded from Unity's GitHub repository and easily imported into a project.
  • By following the steps outlined in this article, developers can successfully implement animation instancing and achieve smooth framerates in their Unity projects.

❓ Frequently Asked Questions

Q: Can animation instancing be used with custom shaders? A: Yes, animation instancing works with shaders, and developers can modify their own shaders to be compatible with animation instancing using instructions provided by Unity.

Q: Does animation instancing work on all platforms? A: Yes, animation instancing is compatible with multiple platforms and can be built for the target platform using the Asset Bundle Browser package.

Q: What is the expected performance improvement when using animation instancing? A: Animation instancing significantly reduces the number of batches, resulting in improved performance and smoother framerates in scenes with a large number of models.

Q: Can animation instancing be applied to different types of models or is it limited to specific assets? A: Animation instancing can be applied to any animated model in Unity, allowing developers to create diverse and visually impressive scenes with optimal performance.

Most people like