Lecture on Unity Optimization for Mobile Games
Audience Considerations
- Mostly programmers familiar with Unity
- Majority have over 5 years of experience
- Primarily developing for low-end Android handsets
Main Focus: Achieving 60 FPS with Unity's URP
Key Metrics and Profiling
- 60 FPS: Requires 16 ms per frame
- Low-end handsets may target 30 ms
- Performance Bottlenecks: Identify if CPU or GPU bound
- Use Unity Profiler to analyze compute time
- Check physics, animations, particle effects, etc.
Using URP (Universal Render Pipeline)
- Pipeline Assets: Create multiple pipeline assets for different devices and configurations
- Analyze device performance during loading screens
- Classify devices into six buckets (very low-end to ultra-high-end)
- Quality Settings: Customize settings for each bucket
- Adjust asset loading times, shadow quality, texture sizes, etc.
- Key Configurations:
- Shadow resolution, cascading shadows
- Texture compression (e.g., crunch compression)
- Per-pixel vs. vertex lighting
- Use
simple lit
shaders for performance
Specific Optimization Techniques
- Shadows:
- Real-time shadows work well on medium to high-end devices
- Cascading shadows for large scenes
- Manual placement of contact shadows for low-end devices
- Lighting:
- Use vertex lighting for low-end devices
- Limit per-pixel lighting to high-end settings
- Multiple light settings (e.g., three directional lights for characters)
- Set Pass Calls: Aim to keep below 100
- Use Unity's Frame Debugger to analyze
- Group objects to minimize different materials
- Triangle Count: Keep around 150K to avoid thermal issues
- Culling settings to manage scene complexity
- Post Processing:
- Use extensively for medium to ultra-high-end
- Disable for low-end to prevent heat issues
- Downsampling:
- Use the
setResolution
function to reduce rendering resolution
- Don’t go below 70% of the native resolution
Other Tips
- Texture Compression: Enable crunch compression to reduce file size
- Dynamic Prefabs: Use shared materials to avoid instance-related set pass issues
Considerations for VR on Mobile
- Resolution: Maintain high resolution; avoid downsampling
- Scene Complexity: Avoid large open-world scenes
- Optimizations: Similar to mobile, focusing on light baking, compressed textures, etc.
Final Points
- Pay close attention to profiling data
- Use Unity tools like Frame Debugger for detailed analysis
- Customize optimizations based on device capabilities and game requirements
Q&A
- VR Optimization: Maintain high resolution and avoid large scenes
- Dynamic Prefabs: Use shared materials to reduce set pass calls
Note: The speaker is available for further questions and help after the session.