Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Unity best practices (2013)

89 views

Published on

Short presentation I've made in companies to help them optimize quickly their mobile games. Entry level, some things are outdated.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Unity best practices (2013)

  1. 1. Unity: Best Practices how to save memory and the world
  2. 2. Point of this meeting We don’t want to see this That’s pretty much it This bullet point is pure decoration
  3. 3. Using ForEach Loops Don’t use them in code that you allow Unity to compile for you Use it to iterate other generic collection (List<T>) with a recent compiler.
  4. 4. Closures and LINQ This code cause minor leak => Closure: this is worse => Not an expert in LINQ but I avoid using it during runtime
  5. 5. Coroutines Coroutines are useful, we can use it. Need to avoid calling StartCoroutine() often on frame- based
  6. 6. Strings Don’t use them… Just kidding, you can Runtime, System.Text.StringBuilder >> String.concat(). if(string == string2) << use string.Equals(string2) faster especially for short strings
  7. 7. Basic Physx Do not use mesh collider Do not move a static collider (can be traced in profiler) There’s A LOT MORE but just covering the basics here
  8. 8. Basic Graphx (CPU) Target ~100 draw calls on mobile Using call batching to reduce meshes number Using atlas texture and fewer materials
  9. 9. Basic Graphx 1-Fillrate (Mobile GPU) It’s all about shading for fillrate Alpha blended not alpha testing Pick lowest number precision format (half, float) Avoid expensive math (pow, exp, log…)
  10. 10. Basic Graphx 2-Bandwith (Mobile GPU) Texture compression / 16-bit Using mipmaps or render size checking Vertex count below 200/300K / not to much overdraw alpha SET STATIC ON NON-MOVING OBJECT FOR BATCH !!!
  11. 11. Tips and Tricks Calling onBecameVisible / onBecameInvisible to stop calling scripts when not rendered Using time-based coroutine instead of update() - Do something every second instead of every frame Struct instead of Class for local Data
  12. 12. Using the tool Network Emu: Useful to test low-bandwidth Unit Tests Editor: Planning test easy VS Debug: Breakpoints, Watch, step by step… Remote profiling for android/iOS
  13. 13. Going further Object Pools, signals, nullable types… GetRuntimeMemorySize(Object) to track memory leaks Useful resources : Optim from ARM CTO Patterns and code SIGGRAPH 2011 Optim Unity Paper
  14. 14. Improving quality Audio, Particles, Lights, image-effects… Procedural content instead of a bunch of assets A 3D world around a 2D game

×