23
2014
Unity Optimization Tips
Making a new post here just to collect Unity Optimization tips (usually not mentioned in docs..)
Feel free to post any tips / links to tips into the comment section also.
OPTIMIZATION TIPS (Not in any order & not all are confirmed to work)
SCRIPTING
– Its better to use Awake() than Start(). Uses less resources *Source: some univ. unity teacher said unity had said so..
GENERAL LINKS
– Lots of tips *New2020
– General performance tips (meshes, lighting, textures, audio, physics, shaders, scripting)
– Unite 2013: Optimizing Games for Mobile Platforms (pdf)
– Optimizing graphics performance (draw calls, geometry, materials, shaders, checklist to make your game faster)
– Optimization Techniques (Update time, saving memory on textures/meshes)
– Practical guide to optimization for mobiles
– Best Practices (cache references, pooling, sharing materials)
– Unity Android Performance Optimization in Domingos
– 50 tips, best practices
– How to use profiler for optimizing (pro only)
–
more will be added later..
Related Posts
110 Comments + Add Comment
Leave a comment
Recent posts
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
If you procedurally generate big meshes, you should probably prefer to use Color32 instead of Color. It’s basically the same, but the arrays of Color32 take 4 times less memory than the arrays of Color.
“If you’re generating meshes with vertex colours in #unity3D use Color32 (Color32 = 4 bytes, Color = 4 floats)”
https://twitter.com/HilariousCow/status/461102706502168576
If you want to highlight an object, there’s no need to replace its material with a temporary copy of it with different parameters – you will need to set the material back and destroy the copy afterwards.
It’s easier to create a MaterialPropertyBlock with the parameters you need and assign it to the object’s renderer using renderer.SetPropertyBlock(…). When you’ve done, just call renderer.SetPropertyBlock(null).
If you do some heavy calculations that may benefit from using SSE technology – use it. Mono.Simd.dll library does work in Unity.
http://tirania.org/blog/archive/2008/Nov-03.html
The library is located here – \Unity\Editor\Data\Mono\lib\mono\2.0\Mono.Simd.dll
If you want to show an object on the screen (especially temporarily), you don’t have to instantiate it. Graphics.DrawMesh is pretty handy in situations when all you really need is just to show a preview.
If you have a terrain with many trees on it, and the trees may be removed (be chopped down, exploded, etc), don’t use colliders on the trees. Tree colliders become a part of the terrain’s collider, you’ll need to update it after a tree has been removed and this update takes quite long if the terrain is large.
Instead, place your tree colliders as a separate independent game objects on the scene. It’s much faster to destroy a single game object than to update the whole terrain’s collider.
It is better to use Awake always, if possible. It runs before every other function and best suits for initialize process. Start() sometimes runs only after GameObject already made an Update() or FixedUpdate().
Live Training: Unity Tips & Tricks (Monday, June 23rd at 22:00)
http://unity3d.com/learn/live-training/session/unity-tips-tricks
part.2:
http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/tips-tricks-2
also,
Internal Unity tips and tricks:
http://unity3d.com/learn/resources/talks/internal-unity-tips-and-tricks
Performance Optimization Tips and Tricks for Unity (video + slides)
http://unity3d.com/unite/archive/2012
shader, “nolightmap”
http://forum.unity3d.com/threads/reserved-samplers-in-surface-shaders.253846/#post-1678148
also in docs,
“nolightmap – Disables lightmap support in this shader (makes a shader smaller)”
about BitConverter (not directly unity related..)
http://forum.unity3d.com/threads/solved-load-a-16bit-wav-file-without-using-www-at-runtime.255572/#post-1691741
about shaders: ” If you don’t want lighting at all, you should write a vertex/fragment shader by hand”
http://forum.unity3d.com/threads/to-lambert-or-to-not-lambert.257175/#post-1699430
about OnTriggerStay2D (better use boolean + OnTriggerEnter2D & OnTriggerExit2D instead)
http://forum.unity3d.com/threads/best-way-to-interact-with-something.256984/#post-1698422
about memory usage and DXT5/DXT1 compression:
http://forum.unity3d.com/threads/tips-and-tricks-make-sure-to-profile-your-phone-apps-memory-usage.202952/
Make OnGui() faster with useGUILayout = false:
http://forum.unity3d.com/threads/gui-that-hidden-bastard.257383/#post-1700795
http://docs.unity3d.com/ScriptReference/MonoBehaviour-useGUILayout.html
about transparency performance in ios GPU:
http://forum.unity3d.com/threads/unity-shaders-that-lead-to-overdraw-problems.261524/#post-1730416
C# Coroutine WaitForSeconds Garbage Collection tip:
http://forum.unity3d.com/threads/c-coroutine-waitforseconds-garbage-collection-tip.224878/
tips & tricks twitter:
https://twitter.com/tips4unity
Mobile performance poor man’s tips and tricks:
https://youtu.be/KvzKhMBL-jI?list=PLX2vGYjWbI0RP5YmvwgqgJQrHGul-Tnr_
The “Optimization Techniques (Update time, saving memory on textures/meshes)” link has changed to http://www.mel-georgiou.co.uk/category/unity3d-tutorials/unity3d-optimization-techniques/
Unity 3D Best Practices: Physics : http://x-team.com/2014/05/unity-3d-best-practices-physics/
enable sprite packing in editor also (not just builds), to get UI elements batched:
http://forum.unity3d.com/threads/new-ugui-and-too-many-draw-calls.266631/#post-1762490
about UI batching:
“batching looks at Rect overlaps, so if there are overlaps between non batchable elements then it will break batching”
http://forum.unity3d.com/threads/rawimage-breaks-batching.266632/#post-1765242
Unity design patterns and concepts:
http://www.reddit.com/r/Unity3D/comments/1nb06h/unity_design_patterns_and_concepts_looking_for/
Optimizing shuriken particles
http://ethicmotion.blogspot.com/2014/06/unity3d-optimizing-shuriken-particle.html
about “grabpass slower than rendertextures”
http://forum.unity3d.com/threads/2d-water-shader.182051/#post-1809190
Some general Unity 3D tips (using the editor)
http://www.codeproject.com/Tips/847987/Some-Quick-Unity-d-Tips
fixing missing references:
http://www.tallior.com/fixing-missing-references/
Reducing Unity game file size:
http://www.gamedev.net/blog/591/entry-2260598-reducing-unity-game-file-size/
using ‘-unsafe’:
http://forum.unity3d.com/threads/unity-free-plugins-and-native-dlls.181401/#post-1892694
Some tips and tricks for unity optimization techniques (especially for Android) can be found here http://www.slideshare.net/AlexanderDolbilov/google-i-o-2014
wow, thats interesting stuff, thanks!
Unity Math/Physics Optimizations:
http://www.performancesimulations.com/wp/how-to-get-big-speed-increases-in-unitys-physics-or-any-math-heavy-code/
“Fast but no exceptions”, transform.position ~3x faster:
http://forum.unity3d.com/threads/how-much-slower-is-slow-and-safe-vs-fast-but-no-exceptions.150254/#post-1033345
optimized Lerp:
http://forum.unity3d.com/threads/there-are-some-big-issues-with-unitys-lerp-tutorial-who-can-i-talk-to-about-it.291518/#post-1923549
Free allocation-free LINQ replacement and JIT Exception Avoidance:
http://forum.unity3d.com/threads/smooth-foundations-free-allocation-free-linq-replacement-and-jit-exception-avoidance.245186/
comparing calculations:
http://forum.unity3d.com/threads/fastest-way-to-find-nearest-enemy-in-front-of-player.121128/#post-1948400
transform.position vs. transform.localPosition and about “When dealing with Vectors/Quaternion, its faster to do the math yourself ”
http://forum.unity3d.com/threads/could-batched-vector-ops-speed-up-unity.253924/#post-1677880
UI performance, pixel perfect off:
http://forum.unity3d.com/threads/can-the-scrollrect-performance-issue-even-be-fixed.297258/#post-1968304
Performance question – “for loop twice” VS “for loop with modulus + division” :
http://forum.unity3d.com/threads/performance-question-for-loop-twice-vs-for-loop-with-modulus-division.307222/
To get the minimal .ipa Size of Unity Apps:
http://forum.unity3d.com/threads/iphone6-6-and-ios8-xcode6-first-hand-on-experience-with-unity.269422/#post-1918915
External tool:
PNG compress (up to 70%)
http://pngquant.org/
audio latency:
http://forum.unity3d.com/threads/impossible-to-do-a-rhythm-game-with-unity-due-to-latency.106034/#post-701517
Unity UI Best Practices:
http://forum.unity3d.com/threads/unity-ui-best-practices.313416/
General tips & keyboard shortcuts:
http://www.develop-online.net/tools-and-tech/top-tips-10-things-you-didn-t-know-you-could-do-with-unity/0204730
“What we learned trying to optimize our game using Unity3D” (lots of good tips!)
http://www.gamasutra.com/blogs/AmirFassihi/20130828/199134/0__60_fps_in_14_days_What_we_learned_trying_to_optimize_our_game_using_Unity3D.php
2D Puppet Rigging – Tips Tricks:
http://forum.unity3d.com/threads/2d-puppet-rigging-tips-tricks.245564/
collection of short unity tips & tricks:
http://unitytip.com
Debug shaders in visual studio:
http://forum.unity3d.com/threads/debugging-shaders-in-visual-studio.322186/
about setpass:
http://forum.unity3d.com/threads/setpass.323678/
access mip map in shader:
http://forum.unity3d.com/threads/avoiding-grabpass.174708/#post-1196400
C# memory and performance tips for Unity:
http://www.somasim.com/blog/2015/04/csharp-memory-and-performance-tips-for-unity/
C# performance tips for Unity, part 2: structs and enums
http://www.somasim.com/blog/2015/08/c-performance-tips-for-unity-part-2-structs-and-enums/
Code Optimization Practices (with code examples)
http://forum.unity3d.com/threads/code-optimization-practices.324852/
Big-O complexities of common algorithms:
http://bigocheatsheet.com/
How To Plan Optimizations with Unity:
https://software.intel.com/en-us/articles/how-to-plan-optimizations-with-unity
Unity Internals: Memory and Performance:
http://www.slideshare.net/flashgamm/unity-internals-memory-and-performance
“object.ReferenceEquals(someObject, null) is faster than someObject == null”
https://twitter.com/mikegeig/status/603160543642263552
^speedtest
https://twitter.com/mikegeig/status/603254742614159360
ios native video example:
http://forum.unity3d.com/threads/is-there-a-way-to-unload-a-movie-from-memory-on-ios.328424/
about grabpass and tex2D,
http://forum.unity3d.com/threads/optimize-shader.328540/#post-2132681
make your own deltaTime:
http://forum.unity3d.com/threads/game-slower-faster-on-different-computers.69124/#post-2133045
Using terrain on mobiles:
http://forum.unity3d.com/threads/the-secret-to-great-terrain-on-mobile.305899/
(Tutorial) Unity and DLLs: C# (managed) and C++ (unmanaged)
http://ericeastwood.com/blog/17/unity-and-dlls-c-managed-and-c-unmanaged
“Mathf is really just a wrapper around System.Math that does the double to float conversion for you”
http://forum.unity3d.com/threads/mathf-for-doubles.339219/#post-2193938
division vs multiplication vs bitshifts
http://forum.unity3d.com/threads/how-to-remove-digits-from-my-int-value.175748/#post-2216401
“define the samplers separate from the textures”
http://forum.unity3d.com/threads/blending-5-materials-with-rgb-normal-height-specular-rough-metal.344148/#post-2225833
old general optimization programming tricks: (links at the bottom)
http://www.hackersdelight.org/
faster math: (lerp3, clamp, smoothstep, round..)
http://forum.unity3d.com/threads/faster-math.23784/
About mesh importer “[x] Read/Write Enabled”
http://forum.unity3d.com/threads/unity-reuploading-mesh-data-for-static-object-every-frame.350374/
deep hierarchies slow down unity:
http://forum.unity3d.com/threads/optimizing-performance-of-many-rigidbodies.349678/#post-2277073
garbage collection tips:
http://forum.unity3d.com/threads/c-why-is-this-code-be-causing-so-much-garbage-collection.349937/#post-2265220
ARM Guide to Unity : Enhancing your mobile games
http://malideveloper.arm.com/documentation/developer-guides/arm-guide-unity-enhancing-mobile-games/
https://youtu.be/Z5y-PQIpSbw
Intel Graphics Performance Analyzers:
https://software.intel.com/en-us/gpa
Unity X86 – Getting the best game experience on Intel Architecture – Unite Europe 2015
https://youtu.be/obkI5mqAXEY?t=8m44s
Unity profiler, GPU stats:
– If Sampler bottleneck: texture size is limiting factor
– If Execution units are stalled in pixels shader: Pixel shader too complex
Mobile optimisation techniques – Unite Europe 2015
https://youtu.be/4lAam8Marns
Discussion about performance tips (including list vs. array vs dictionary comparisons)
http://forum.unity3d.com/threads/latest-performance-tips.355709/
Squeezing Performance out of your Unity Gear VR Game:
https://developer.oculus.com/blog/squeezing-performance-out-of-your-unity-gear-vr-game/
checklist for basic optimizations:
http://forum.unity3d.com/threads/optimization-how-does-it-work.357222/#post-2311100
shader tips:
http://forum.unity3d.com/threads/billboards-generated-with-a-geometry-shader-cant-cast-receive-shadows.387774/#post-2524202
vector2 addition comparison with c# vs unity (and using SIMD)
http://forum.unity3d.com/threads/unity-is-factor-10-slower-than-normal-c-why.391100/#post-2549524
in xcode build, inside fileUnityAppController.mm, there is comment about saving memory:
// if you wont use keyboard you may comment it out at save some memory
[KeyboardDelegate Initialize];
scene file contains old data?
http://forum.unity3d.com/threads/why-is-one-blank-scene-10mb-while-another-is-only-600-kb-do-scene-files-retain-past-data.391519/
pre-calculated sin cos arrays
http://unitycoder.com/blog/2012/01/02/precalculated-sin-cos-arrays/
rendertexture grabpixels is slow, if camera has clear flags: depth only
http://forum.unity3d.com/threads/rendertexture-grabpixels-low-fps-solved.267223/
recommended order for placing image effects:
http://forum.unity3d.com/threads/is-there-any-recommended-sequence-for-placing-image-effects.411116/#post-2679565
Lots of memory related optimizations and tips
http://richg42.blogspot.sg/2015/05/lessons-learned-while-fixing-memory.html
TheBest(tm) mobile optimization video
https://youtu.be/j4YAY36xjwE
Image effects mobile
http://forum.unity3d.com/threads/should-i-avoid-onrenderimage-for-performance-reason.427006/
android performance tips
https://forum.unity3d.com/threads/unity-5-android-performance-tips.437695/
get smaller .apk builds
https://forum.unity3d.com/threads/how-to-reduce-the-android-app-build-size.438119/#post-2843777
New optimization tutorials at Unity Learn
https://unity3d.com/learn/tutorials/topics/performance-optimization
Unite 2016 – Shader Profiling and Optimization
https://youtu.be/4TbvHqf0U04
Unite 2016 – Let’s Talk (Content) Optimization
https://youtu.be/n-oZa4Fb12U
The Bestest(tm) New Optimization tips video
shader optimizations
https://forum.unity3d.com/threads/need-help-afraid-of-premature-optimization-to-mobile-uber-shader-writing.463475/
Faster Equal Vector3 Check
https://gist.github.com/unitycoder/187ee364b803ba038f0e12e2a35484ff
struct vs class
http://jacksondunstan.com/articles/3860
Tips and Tricks for Optimizing UI
https://www.slideshare.net/UnityTechnologiesJapan/unite-2017-tokyounity-ui
Optimizing Unity – Saving CPU & Memory
https://www.slideshare.net/UnityTechnologiesJapan/unite-2017-tokyounity-cpu
improved int/float parse
http://wiki.unity3d.com/index.php/FastObjImporter
mobile optimization tips (for gearvr, but valid for others too)
https://developer.oculus.com/blog/squeezing-performance-out-of-your-unity-gear-vr-game
https://developer.oculus.com/blog/squeezing-performance-out-of-your-unity-gear-vr-game-continued
Vector3 and other structs optimization of operators
https://forum.unity3d.com/threads/vector3-and-other-structs-optimization-of-operators.477338/
Unite Europe 2017 – Squeezing Unity: Tips for raising performance (slides)
https://www.slideshare.net/secret/xLig7llwdlRQIp
After I originally left a comment I seem to have clicked
the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the same comment.
Is there a way you are able to remove me from that service?
Thanks a lot!
can you try disabling it from here?
https://wordpress.com/log-in?redirect_to=%2Fsettings%2Fdiscussion%2F
Diagnosing performance issues in Unity
https://medium.com/@shahriyarshahrabi/diagnosing-performance-issues-in-unity-c1fab81790b3
Android, you can force unitymain-thread to run on a fixed core (instead of having it hopping between cores by default, which invalidates caches etc.). Can get ~5% gains.
https://youtu.be/KbxiGH6igBk?t=1778
practical optimizations (very good!)
https://youtu.be/NAVbI1HIzCE