{"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_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":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":[{"id":562,"url":"https:\/\/magiteker.com\/index.php\/2016\/10\/23\/unity-design-patterns\/","url_meta":{"origin":739,"position":0},"title":"Unity Design Patterns: Scriptable Objects","author":"Frank O'Hanlon","date":"October 23, 2016","format":false,"excerpt":"An interesting use of Scriptable Objects within Unity as demonstrated at Unite 2016. video Data Scriptable Object Data Scriptable Manager \u00a0 Instanced Scriptable Object \u00a0","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/magiteker.com\/index.php\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/10\/Unity_Pattern_Logo2.png?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/10\/Unity_Pattern_Logo2.png?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/10\/Unity_Pattern_Logo2.png?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/10\/Unity_Pattern_Logo2.png?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/10\/Unity_Pattern_Logo2.png?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":355,"url":"https:\/\/magiteker.com\/index.php\/2015\/10\/23\/unity-shader-experiments\/","url_meta":{"origin":739,"position":1},"title":"Unity Shader Primer","author":"Frank O'Hanlon","date":"October 23, 2015","format":false,"excerpt":"Shaders are one of the more obscure technologies within the Unity game engine, and while the documentation covers most of the shader language and functions it fails to provide comprehensive techniques that would result in compelling graphics. They're core focus appears to be that of treating shaders as a black\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/magiteker.com\/index.php\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2015\/10\/shader_experiment.png?fit=822%2C463&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2015\/10\/shader_experiment.png?fit=822%2C463&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2015\/10\/shader_experiment.png?fit=822%2C463&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2015\/10\/shader_experiment.png?fit=822%2C463&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":517,"url":"https:\/\/magiteker.com\/index.php\/2016\/09\/02\/unity-synthesizer\/","url_meta":{"origin":739,"position":2},"title":"Unity Audio Wave Tutorial","author":"Frank O'Hanlon","date":"September 2, 2016","format":false,"excerpt":"Games are dynamic systems responding on different types of data inputs to create interesting results for the player. One such source of data is Audio which can at its best help the player have an emotional connection to what's happening on screen. So with this in mind utilizing audio is\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/magiteker.com\/index.php\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/09\/SynthEffect.png?fit=1154%2C418&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/09\/SynthEffect.png?fit=1154%2C418&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/09\/SynthEffect.png?fit=1154%2C418&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/09\/SynthEffect.png?fit=1154%2C418&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2016\/09\/SynthEffect.png?fit=1154%2C418&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1382,"url":"https:\/\/magiteker.com\/index.php\/2023\/06\/21\/resource-training-stable-diffusion-with-dreambooth\/","url_meta":{"origin":739,"position":3},"title":"Resource: Training Stable Diffusion with Dreambooth","author":"Frank O'Hanlon","date":"June 21, 2023","format":false,"excerpt":"-Blog Post This article describes experiments with different Learning Rates in training models using Dreambooth. FTA: Summary of Initial Results To get good results training Stable Diffusion with Dreambooth, it's important to tune the learning rate and training steps for your dataset. High learning rates and too many training steps\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/magiteker.com\/index.php\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":75,"url":"https:\/\/magiteker.com\/index.php\/2015\/09\/27\/fluid-simulation\/","url_meta":{"origin":739,"position":4},"title":"Fluid Simulation","author":"Frank O'Hanlon","date":"September 27, 2015","format":false,"excerpt":"Using cellular automata I implemented a simple fluid simulation into the Unity Engine. Each cell in this implementation represents a unit in space containing either fluid, air, or solid mass. For each frame of the simulation a calculation is made attempting to move all the fluid into a state of\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/magiteker.com\/index.php\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/magiteker.com\/wp-content\/uploads\/2015\/09\/fluid0.png?fit=513%2C321&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"_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}]}}