{"id":739,"date":"2016-12-11T22:26:56","date_gmt":"2016-12-11T22:26:56","guid":{"rendered":"http:\/\/magiteker.com\/?p=739"},"modified":"2017-02-17T04:07:02","modified_gmt":"2017-02-16T22:07:02","slug":"unity-design-patterns-memory-management","status":"publish","type":"post","link":"https:\/\/magiteker.com\/index.php\/2016\/12\/11\/unity-design-patterns-memory-management\/","title":{"rendered":"Unity Design Patterns: Optimization"},"content":{"rendered":"<p style=\"text-align: left;\">Some low level optimizations present at Unite Los Angeles and Unite Europe 2016.<\/p>\n<h2 style=\"text-align: center;\">Unite Los Angeles 2016<\/h2>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/n-oZa4Fb12U\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<ul>\n<li style=\"text-align: left;\">Move configuration data to Scriptable Objects.<\/li>\n<li style=\"text-align: left;\">Utilize the new instantiate call when parenting an object.<\/li>\n<li style=\"text-align: left;\">Don&#8217;t needlessly parent objects in production.<\/li>\n<li style=\"text-align: left;\">Batch changes to Transforms in order to save on transform change message calls.<\/li>\n<li style=\"text-align: left;\">Optimize game object transforms utilizing the Mecanim system.<\/li>\n<li style=\"text-align: left;\">Move static and dynamic canvas elements onto nested separate canvas.<\/li>\n<li style=\"text-align: left;\"><a href=\"https:\/\/unity3d.com\/learn\/tutorials\/topics\/best-practices\">Best Practices<\/a><\/li>\n<\/ul>\n<hr \/>\n<h2 style=\"text-align: center;\">Unite Europe 2016<\/h2>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/j4YAY36xjwE\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<ul>\n<li style=\"text-align: left;\"><a href=\"https:\/\/bitbucket.org\/Unity-Technologies\/memoryprofiler\">Memory Profiler<\/a><\/li>\n<li style=\"text-align: left;\">Utilize AssetPostProcessor class to enforce project asset rules.<\/li>\n<li style=\"text-align: left;\">Disable Write for textures unless performing pixel operations.<\/li>\n<li style=\"text-align: left;\">Disable Mipmaps for UI and 2D textures.<\/li>\n<li style=\"text-align: left;\">Compress textures whenever possible.<\/li>\n<li style=\"text-align: left;\">Disable Read\/Write for models to save mesh memory, unless using Mesh Colliders.<\/li>\n<li style=\"text-align: left;\">Disable Rig on non-character models.<\/li>\n<li style=\"text-align: left;\">Copy avatars for characters with shared rigs.<\/li>\n<li style=\"text-align: left;\">Enable mesh compression.<\/li>\n<li style=\"text-align: left;\">Audio files should be forced to Mono to save memory.<\/li>\n<li style=\"text-align: left;\">The Heap only expands at run-time, so manage allocations carefully.<\/li>\n<li style=\"text-align: left;\">Avoid using strings, utilize <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.text.stringbuilder(v=vs.110).aspx\">StringBuilders<\/a>\u00a0instead.<\/li>\n<li style=\"text-align: left;\">Avoid Closures and anonymous functions due to heap allocations<\/li>\n<li style=\"text-align: left;\">Avoid <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/yz2be5wk.aspx\">Boxing<\/a> with Enums, instead create an IEqualityComparer class and pass it to your data structure.<\/li>\n<li style=\"text-align: left;\">Avoid Foreach loops.<\/li>\n<li style=\"text-align: left;\">Avoid parsers that utilize <a href=\"https:\/\/en.wikipedia.org\/wiki\/Reflection_(computer_programming)\">Reflection<\/a>, it&#8217;s suggested to use Unity&#8217;s JsonUtility class for parsing.<\/li>\n<li style=\"text-align: left;\">When using Shader ID&#8217;s hash the string ID&#8217;s at startup and save them for reuse.<\/li>\n<li style=\"text-align: left;\">Avoid Vector3.zero and Quaternion.identity instead utilize const values for simple types and static readonly for complex types.<\/li>\n<li style=\"text-align: left;\"><strong>Only use these optimizations as needed.<\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Some low level optimizations present at Unite Los Angeles and Unite Europe 2016. Unite Los Angeles 2016 Move configuration data to Scriptable Objects. Utilize the new instantiate call when parenting an object. Don&#8217;t needlessly parent objects in production. Batch changes to Transforms in order to save on transform change message calls. Optimize game object transforms [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":570,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[21],"tags":[],"class_list":["post-739","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/10\/Unity_Pattern_Logo2.png?fit=1920%2C1080&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6MIgq-bV","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/posts\/739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/comments?post=739"}],"version-history":[{"count":11,"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/posts\/739\/revisions"}],"predecessor-version":[{"id":759,"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/posts\/739\/revisions\/759"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/media\/570"}],"wp:attachment":[{"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/media?parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/categories?post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/magiteker.com\/index.php\/wp-json\/wp\/v2\/tags?post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}