Game Development

Optimizing Unity Games for Mobile & Web

A comprehensive guide to maximizing performance and delivering smooth gameplay experiences across platforms

12 min read
Advanced
Unity 2023+

Performance optimization is crucial for delivering quality gaming experiences on mobile and web platforms. Unity games must run smoothly on devices with varying capabilities while maintaining visual fidelity and engaging gameplay. This guide covers essential optimization techniques that will help you achieve 60 FPS performance across different platforms.

60
Target FPS
50%
Typical Performance Gain
3x
Battery Life Improvement

Graphics Optimization

Texture Management

Textures often consume the most memory in Unity games. Proper texture optimization can dramatically reduce memory usage and improve loading times.

// Example: Programmatic texture compression
TextureImporter importer = (TextureImporter)assetImporter;
importer.textureCompression = TextureImporterCompression.Compressed;
importer.compressionQuality = 50; // Balance quality vs size
importer.maxTextureSize = 2048;
importer.mipmapEnabled = true;

Mesh and Model Optimization

3D models should be optimized to reduce polygon count while maintaining visual quality through efficient use of textures and normal maps.

Pro Tip: LOD Groups

Unity's LOD Group component can automatically swap between different mesh resolutions. Set up at least 3 LOD levels: high detail (0-25m), medium (25-50m), and low (50m+) with a billboard or disable for very far distances.

Shader Optimization

Complex shaders can bring even powerful GPUs to their knees on mobile devices. Simplifying shaders is one of the fastest ways to improve performance.

Code and Logic Optimization

Efficient Scripting Practices

Well-written code can mean the difference between smooth 60 FPS gameplay and choppy performance.

// Bad: Allocates new array every frame
void Update() {
    foreach (var enemy in FindObjectsOfType<Enemy>()) {
        enemy.UpdateBehavior();
    }
}

// Good: Cache and reuse
private Enemy[] enemies;
void Start() {
    enemies = FindObjectsOfType<Enemy>();
}
void Update() {
    foreach (var enemy in enemies) {
        enemy.UpdateBehavior();
    }
}

Physics Optimization

Physics calculations can be computationally expensive, especially with many colliders and rigidbodies in the scene.

Common Pitfall: Raycasts in Update

Performing raycasts every frame for every object is extremely expensive. Instead, use raycasts sparingly, cache results when possible, or use Unity's job system for parallel processing of multiple raycasts.

Mobile-Specific Optimizations

Resolution and Rendering

Mobile devices have limited GPU power and thermal constraints. Adjust rendering settings to maintain performance.

Memory Management

Mobile devices have strict memory limits. Exceeding them can cause crashes or OS killing your app.

WebGL Optimization

Build Size Reduction

WebGL builds are downloaded by users, so smaller file sizes mean faster loading and better user retention.

// Player Settings for WebGL optimization
PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Brotli;
PlayerSettings.WebGL.memorySize = 256; // Limit to 256MB
PlayerSettings.SetManagedStrippingLevel(
    BuildTargetGroup.WebGL, 
    ManagedStrippingLevel.High
);

Runtime Performance

WebGL runs in browsers with additional constraints compared to native platforms.

WebAssembly Performance

Unity WebGL builds use WebAssembly (WASM) for better performance than JavaScript. Ensure your server sends the correct MIME types: application/wasm for .wasm files and enable compression headers for .br (Brotli) files.

Testing and Profiling

Profiling Tools

You can't optimize what you don't measure. Use Unity's built-in profiling tools to identify bottlenecks.

Performance Targets

Establish clear performance budgets for your project based on target devices and platforms.

<16ms
Frame Time (60 FPS)
<100
Draw Calls
<50k
Triangles On Screen