Book description
Master a series of performance-enhancing coding techniques and methods that help them improve the performance of their Unity3D applications
About This Book
- Discover features and techniques to optimize Unity Engine's CPU cycles, memory usage, and the GPU throughput of any application
- Explore multiple techniques to solve performance issues with your VR projects
- Learn the best practices for project organization to save time through an improved workflow
Who This Book Is For
This book is intended for intermediate and advanced Unity developers who have experience with most of Unity's feature-set, and who want to maximize the performance of their game. Familiarity with the C# language will be needed.
What You Will Learn
- Use the Unity Profiler to find bottlenecks anywhere in your application, and discover how to resolve them
- Implement best practices for C# scripting to avoid common pitfalls
- Develop a solid understanding of the rendering pipeline, and maximize its performance by reducing draw calls and avoiding fill rate bottlenecks
- Enhance shaders in a way that is accessible to most developers, optimizing them through subtle yet effective performance tweaks
- Keep your scenes as dynamic as possible by making the most of the Physics engine
- Organize, filter, and compress your art assets to maximize performance while maintaining high quality
- Discover different kinds of performance problems that are critical for VR projects and how to tackle them
- Use the Mono Framework and C# to implement low-level enhancements that maximize memory usage and avoid garbage collection
- Get to know the best practices for project organization to save time through an improved workflow
In Detail
Unity is an awesome game development engine. Through its massive feature-set and ease-of-use, Unity helps put some of the best processing and rendering technology in the hands of hobbyists and professionals alike.
This book shows you how to make your games fly with the recent version of Unity 2017, and demonstrates that high performance does not need to be limited to games with the biggest teams and budgets.
Since nothing turns gamers away from a game faster than a poor user-experience, the book starts by explaining how to use the Unity Profiler to detect problems. You will learn how to use stopwatches, timers and logging methods to diagnose the problem. You will then explore techniques to improve performance through better programming practices.
Moving on, you will then learn about Unity's built-in batching processes; when they can be used to improve performance, and their limitations. Next, you will import your art assets using minimal space, CPU and memory at runtime, and discover some underused features and approaches for managing asset data. You will also improve graphics, particle system and shader performance with a series of tips and tricks to make the most of GPU parallel processing.
You will then delve into the fundamental layers of the Unity3D engine to discuss some issues that may be difficult to understand without a strong knowledge of its inner-workings. The book also introduces you to the critical performance problems for VR projects and how to tackle them.
By the end of the book, you will have learned to improve the development workflow by properly organizing assets and ways to instantiate assets as quickly and waste-free as possible via object pooling.
Style and approach
This practical book will help readers understand the essentials of the Unity3D engine and how to build games while improving the performance of their applications.
Table of contents
- Preface
- Pursuing Performance Problems
-
Scripting Strategies
- Obtain Components using the fastest method
- Remove empty callback definitions
- Cache Component references
- Share calculation output
- Update, Coroutines, and InvokeRepeating
- Faster GameObject null reference checks
- Avoid retrieving string properties from GameObjects
- Use appropriate data structures
- Avoid re-parenting Transforms at runtime
- Consider caching Transform changes
- Avoid Find() and SendMessage() at runtime
- Disable unused scripts and objects
- Consider using distance-squared over distance
- Minimize Deserialization behavior
- Load scenes additively and asynchronously
- Create a custom Update() layer
- Summary
- The Benefits of Batching
-
Kickstart Your Art
-
Audio
- Importing audio files
- Loading audio files
- Encoding formats and quality levels
-
Audio performance enhancements
- Minimize active Audio Source count
- Enable Force to Mono for 3D sounds
- Resample to lower frequencies
- Consider all compression formats
- Beware of streaming
- Apply Filter Effects through Mixer Groups to reduce duplication
- Use remote content streaming responsibly
- Consider Audio Module files for background music
- Texture files
- Mesh and animation files
- Asset Bundles and Resources
- Summary
-
Audio
-
Faster Physics
- Physics Engine internals
-
Physics performance optimizations
- Scene setup
- Use Static Colliders appropriately
- Use Trigger Volumes responsibly
- Optimize the Collision Matrix
- Prefer Discrete collision detection
- Modify the Fixed Update frequency
- Adjust the Maximum Allowed Timestep
- Minimize Raycasting and bounding-volume checks
- Avoid complex Mesh Colliders
- Avoid complex physics Components
- Let physics objects sleep
- Modify the Solver Iteration Count
- Optimize Ragdolls
- Know when to use physics
- Summary
-
Dynamic Graphics
- The Rendering Pipeline
- Detecting performance issues
-
Rendering performance enhancements
- Enable/Disable GPU Skinning
- Reduce geometric complexity
- Reduce Tessellation
- Employ GPU Instancing
- Use mesh-based Level Of Detail (LOD)
- Make use of Occlusion Culling
- Optimizing Particle Systems
-
Optimizing Unity UI
- Use more Canvases
- Separate objects between static and dynamic canvases
- Disable Raycast Target for noninteractive elements
- Hide UI elements by disabling the parent Canvas Component
- Avoid Animator Components
- Explicitly define the Event Camera for World Space Canvases
- Don't use alpha to hide UI elements
- Optimizing ScrollRects
- Use empty UIText elements for full-screen interaction
- Check the Unity UI source code
- Check the documentation
-
Shader optimization
- Consider using Shaders intended for mobile platforms
- Use small data types
- Avoid changing precision while swizzling
- Use GPU-optimized helper functions
- Disable unnecessary features
- Remove unnecessary input data
- Expose only necessary variables
- Reduce mathematical complexity
- Reduce texture sampling
- Avoid conditional statements
- Reduce data dependencies
- Surface Shaders
- Use Shader-based LOD
- Use less texture data
- Test different GPU Texture Compression formats
- Minimize texture swapping
- VRAM limits
- Lighting optimization
- Optimizing rendering performance for mobile devices
- Summary
- Virtual Velocity and Augmented Acceleration
-
Masterful Memory Management
- The Mono platform
- Code compilation
- Profiling memory
-
Memory management performance enhancements
- Garbage collection tactics
- Manual JIT compilation
- Value types and Reference types
- String concatenation
- Boxing
- The importance of data layout
- Arrays from the Unity API
- Using InstanceIDs for dictionary keys
- foreach loops
- Coroutines
- Closures
- The .NET library functions
- Temporary work buffers
- Object Pooling
- Prefab Pooling
- IL2CPP optimizations
- WebGL optimizations
- The future of Unity, Mono, and IL2CPP
- Summary
- Tactical Tips and Tricks
Product information
- Title: Unity 2017 Game Optimization - Second Edition
- Author(s):
- Release date: November 2017
- Publisher(s): Packt Publishing
- ISBN: 9781788392365
You might also like
book
Unity 2018 Shaders and Effects Cookbook
Bring realism to your games by mastering post-processing effects and advanced shading techniques in Unity 2018 …
book
Physically Based Shader Development for Unity 2017: Develop Custom Lighting Systems
Benefit from the latest rendering tech developments, currently covered only in papers and talks from Siggraph, …
book
Unity 5 Game Optimization
Master performance optimization for Unity3D applications with tips and techniques that cover every aspect of the …
book
Unity 2018 Cookbook - Third Edition
Develop quality game components and solve common gameplay problems with various game design patterns Key Features …