Unity: content and performance¶
Asset loading, memory management, profiling and localization. Render pipelines, shaders and textures are in Rendering and shaders.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 9 Ultimate guide to profiling Unity games (Unity e-book): the baseline profiling workflow.
- 8 Optimize performance for mobile, XR and web games and for consoles and PCs (Unity e-books): platform-specific optimisation checklists.
- 8 Addressables package manual.
- 6 Advanced programming and code architecture (Unity): scripting performance tips covering the PlayerLoop, update managers, caching and pooling.
Key rules¶
Loading, memory and profiling¶
- 8
UNITY-PERF-1Profile with the Unity Profiler connected to a build running on the target device, early and before and after every optimisation, not only in the Editor. Frame-time budgets per platform areGAMEDEV-12in game development. (Unity, Ultimate guide to profiling, Unity Manual, Profiling your application, Unity Manual, Profiler) - 8
UNITY-PERF-2Pair every Addressables load with a release. Addressables uses reference counting, and unreleased handles keep assets in memory. (Addressables, Release assets from memory) - 8
UNITY-PERF-3Avoid managed allocations in per-frame code paths to prevent garbage-collector spikes. (Unity Manual, Optimizing managed memory) - 7
UNITY-PERF-4Keep theResourcesfolder for prototypes and small bootstrap data. Load game content through Addressables (or AssetBundles). (Unity Manual, Load resources at runtime, Addressables overview) - 6
UNITY-PERF-5Pool objects that are created and destroyed often, such as projectiles, effects and UI list items, usingUnityEngine.Pool. (Unity Scripting API, ObjectPool, Unity e-book, Level up your code with design patterns and SOLID)
Localization¶
- 7
UNITY-PERF-6Localize with the Unity Localization package: keep text in String Tables, make entries that insert values or counts Smart Strings, which take named placeholders and choose plural forms by the CLDR rules, and swap language-specific textures, audio and other assets through Asset Tables. This appliesI18N-1,I18N-2andI18N-3. Check layouts with the package's pseudo-localization before translation starts (I18N-14). (Unity, Localization package, String Tables, Smart Strings, Plural Localization Formatter, Asset Tables, Pseudo-Localization)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 Unity Project Auditor, Code view: reports code issues by CPU and memory impact, and marks issues in code called every frame as Major. It recognises per-frame code only through Update methods and coroutines. Runs from the command line in CI. Partly checks
UNITY-PERF-3. - 6 Microsoft.Unity.Analyzers: flags allocating Unity API calls that have cheaper alternatives, for example
RaycastAllinstead ofRaycastNonAlloc(UNT0028). To run them in Unity's own compile and CI, install them as Roslyn analyzers and promote their warnings to errors with a ruleset. Partly checksUNITY-PERF-3. - 6 Unity Performance Testing package: measures profiler markers and custom metrics in the Editor and in built players, from tests that run in CI. It records results; comparing them with a baseline is up to you. Partly checks
UNITY-PERF-1.