shades of play: code analysis/unity performance tips
TRANSCRIPT
Static Code Analysis
• Gendarme
• Unity rules
https://github.com/fderudder/unity-gendarme
GetComponent() Calls
• Cache your components!
• Avoid GetComponent() calls in Update()
• Avoid this:
Empty MonoBehaviour Methods
• Avoid this:
• Overhead!
Profiler
Sounds
• Avoid this:
• Suggestion:
Pooling
• Expensive Instantiate() calls
• Use a pool for game objects that need to be instantiated/killed frequently
• https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling
Profiler: Comparison
General Advice
• Code style/readability (format your code!)
• Use English for all names etc.
• Do not be afraid of refactoring/renaming
• Use a portrait resolution if your game is portrait
• MonoBehaviour/inspector: Use private members with [SerializeField]
• Unity Console (errors/warnings)
Advanced Optimization
C# Memory and performance tips for Unity:
http://www.somasim.com/blog/2015/04/csharp-memory-and-performance-tips-for-unity/
• for-each vs. for etc.
• GC