UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

optimization

[Animator] Conquer GFX Memory Spikes: Boost Play Mode Performance

Solution

optimizationanimatorperformance

Unity 2021.x - Unity 6.3.x

Published Sun, Mar 22

Issue

 The Unity Editor experiences severe memory exhaustion and System out of memory crashes during Play Mode. This typically manifests as massive GFX memory spikes, often exceeding 25GB, even when using Sprite Atlases. The issue is linked to Animator and PlayableDirector components on inactive GameObjects loading textures in an uncompressed state, causing significant allocation overhead.

Explanation

Address excessive memory consumption by optimizing PlayableDirector and Animator states. Unused playables within a PlayableDirector may load referenced images uncompressed and at an enlarged scale, even if they are part of compressed sprite atlases. To mitigate this, ensure PlayableDirector components only reference necessary assets and manage their lifecycle to release resources.

Animators on GameObjects initially set to inactive in the scene hierarchy often load referenced animation textures uncompressed and at larger dimensions. To prevent this, ensure these objects are initially active.

  1. Identify all GameObjects containing an Animator or PlayableDirector that are currently disabled in the hierarchy.
  2. Set these objects to active by default in the Inspector.
  3. Attach your script to these objects to deactivate them during the Start lifecycle phase.

Additional Tips

  • Use the Memory Profiler package to inspect specific PlayableDirector asset references.
  • Verify that the Sprite Atlas is correctly included in the build and that ‘Include in Build’ is enabled.
  • Check if ‘Culling Mode’ on the Animator can be set to ‘Cull Completely’ to save performance when off-screen.

TL;DR

Resolve GFX memory spikes by ensuring GameObjects with Animator components are active at scene load and then programmatically deactivated via the Start method.


Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.