[Animator] Conquer GFX Memory Spikes: Boost Play Mode Performance
Solution
Unity 2021.x - Unity 6.3.x
Published Sun, Mar 22
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.
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.
- Identify all
GameObjectscontaining anAnimatoror PlayableDirector that are currently disabled in the hierarchy. - Set these objects to active by default in the Inspector.
- Attach your script to these objects to deactivate them during the
Startlifecycle phase.
Additional Tips
- Use the
Memory Profilerpackage to inspect specific PlayableDirector asset references. - Verify that the
Sprite Atlasis correctly included in the build and that ‘Include in Build’ is enabled. - Check if ‘Culling Mode’ on the
Animatorcan 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.