Unity Performance and Optimization
Common Causes
Poorly structured code
Garbage collection
Expensive operations (/ vs X)
Demanding scripts
Code for readability -> Profile -> Optimize
Our Notes
Project Setup
BitBucket
Project Architecture
BitBucketFolder
Gamename-platform
Assets
Project Settings
Unity Profiler
For Scripts, only CPU Usage and Memory Usage is needed.
CPU Usage
Change the bottom window to (Hierarchy)
Programming
Multiple instead of divide.
Memory Management
https://www.gamasutra.com/blogs/WendelinReich/20131109/203841/C_Memory_Management_for_Unity_Developers_part_1_of_3.php
https://www.slideshare.net/williamyang3910/unitekorea2013-memory-profiling-in-unity
http://richg42.blogspot.com/2015/05/lessons-learned-while-fixing-memory.html
https://stackoverflow.com/questions/41768846/unity-profiling-my-scripts-memory-usage
https://forum.unity.com/threads/ios-large-memory-usage-apparently-feature-not-a-bug.637660/
https://forum.unity.com/threads/unityvideo-player-memory-leak-in-pc-builds.504617/
https://thoughtbot.com/blog/avoiding-out-of-memory-crashes-on-mobile
https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html
https://docs.unity3d.com/ScriptReference/Networking.DownloadHandlerBuffer.html
https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html
https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/39
https://stackoverflow.com/questions/42944713/unity-5-6-ram-usage-continues-to-grow
https://dzone.com/articles/avoiding-out-of-memory-crashes-on-mobile
https://www.reddit.com/r/Unity3D/comments/5p3q6w/are_memory_leaks_an_issue_with_unity_c/
https://www.quora.com/How-can-we-solve-the-iOS-app-crashing-issue-made-by-Unity-3D
https://docs.microsoft.com/en-us/dotnet/api/system.io.filestream.read?view=netframework-4.8
https://stackoverflow.com/questions/16862782/streaming-large-video-files-net
Get Total Memory
long memoryUsed = System.GC.GetTotalMemory(true); float megaBytes = Mathf.Pow(2, 20); var memoryUsedInMb = memoryUsed / megaBytes;
Avoiding Out of Memory Crashes on Mobile
Refs:
https://thoughtbot.com/blog/avoiding-out-of-memory-crashes-on-mobile
Performance
https://catlikecoding.com/unity/tutorials/frames-per-second/
https://learn.unity.com/tutorial/fixing-performance-problems#
https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity.html
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/boxing-and-unboxing
https://learn.unity.com/tutorial/live-sessions-on-scripting#5c7f8528edbc2a002053b628
https://en.wikipedia.org/wiki/Object_pool_pattern
Profiling
https://github.com/ahmedmohi/iProfiler/blob/master/Assets/iProfiler/StatsMan.cs
Images
var textures = Resources.FindObjectsOfTypeAll(typeof(Texture2D));
int totalBytes = 0;
foreach (Texture2D t in textures)
{
int memorySize = Profiler.GetRuntimeMemorySize(t);
if (memorySize > 0.4f)
Debug.Log(“Texture object “ + t.name + “(“ + t.width + “x” + t.height + “|” + t.format + “) using: “ + memorySize + “Bytes”, t);
totalBytes += memorySize;
}
Debug.Log(“Total bytes: “ + totalBytes);
Build Size
Binary Size
https://www.youtube.com/watch?time_continue=344&v=4JLpJHIdx7E
https://files.unity3d.com/jonas/BuildReportInspector.zip
Framerate and VSync
Set VSync to 0
Optimization Tips
Project Setup
BitBucket
Project Architecture
BitBucketFolder
Gamename-platform
Assets
Project Settings
Unite Europe 2017 - Squeezing Unity: Tips for raising performance
https://www.youtube.com/watch?v=_wxitgdx-UI
Make a game fun, then make it fast
UI is shit!!!!
https://www.slideshare.net/secret/xLig7llwdlRQIp
https://www.youtube.com/watch?v=_wxitgdx-UI
https://www.slideshare.net/secret/xLig7llwdlRQIp
https://www.youtube.com/watch?v=c6sLiFIFd8o
https://www.youtube.com/watch?v=eH-PdFKgctE
https://www.youtube.com/watch?v=1e5WY2qf600
https://www.youtube.com/watch?v=j4YAY36xjwE&t=1765s
https://www.youtube.com/watch?v=1e5WY2qf600
References
https://www.youtube.com/watch?v=kML67qB9Chk
https://blog.unity.com/technology/customize-your-memory-use-with-unity-2021-lts
http://devmag.org.za/2012/07/12/50-tips-for-working-with-unity-best-practices/
https://www.reddit.com/r/gamedev/comments/4xyxeh/50_tips_and_best_practices_for_unity_2016_edition/
http://portal.babelx3d.net/content/50-tips-and-best-practices-unity
http://wiki.unity3d.com/index.php?title=General_Performance_Tips
https://www.3dbuzz.com/forum/threads/193421-50-Tips-for-Working-with-Unity-(Best-Practices)
https://www.scribd.com/document/327675440/50-Tips-and-Best-Practices-for-Unity-2016-Edition-pdf
https://www.pinterest.com/pin/540713498993949780/
https://www.reddit.com/r/Unity3D/comments/5qwdhy/top_10_unity_tips_2017/
https://blogs.unity3d.com/2017/08/10/spotlight-team-best-practices-project-setup/
http://devmag.org.za/2012/07/12/50-tips-for-working-with-unity-best-practices/
https://www.reddit.com/r/gamedev/comments/4xyxeh/50_tips_and_best_practices_for_unity_2016_edition/
http://portal.babelx3d.net/content/50-tips-and-best-practices-unity
http://wiki.unity3d.com/index.php?title=General_Performance_Tips
https://www.3dbuzz.com/forum/threads/193421-50-Tips-for-Working-with-Unity-(Best-Practices)
https://www.scribd.com/document/327675440/50-Tips-and-Best-Practices-for-Unity-2016-Edition-pdf
https://www.pinterest.com/pin/540713498993949780/
https://www.reddit.com/r/Unity3D/comments/5qwdhy/top_10_unity_tips_2017/
https://blogs.unity3d.com/2017/08/10/spotlight-team-best-practices-project-setup/
Unite Austin 2017 - The Walking Dead: March to War - Rendering 10K Objects on Low-End Mobile Devices
https://youtu.be/hUZbkqLRYus
From Rider:
https://github.com/JetBrains/resharper-unity/wiki/Performance-critical-context-and-costly-methods