{"id":148,"date":"2014-10-15T20:10:23","date_gmt":"2014-10-15T20:10:23","guid":{"rendered":"http:\/\/raheelyawar.com\/?p=148"},"modified":"2014-10-15T20:10:23","modified_gmt":"2014-10-15T20:10:23","slug":"unity-engine-tips-best-practices-mobile-games","status":"publish","type":"post","link":"http:\/\/raheelyawar.com\/?p=148","title":{"rendered":"Unity Engine Tips &#038; Best Practices &#8211; Mobile Games"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"size-medium wp-image-149 alignright\" src=\"https:\/\/i0.wp.com\/159.89.19.162\/wp-content\/uploads\/2017\/10\/gdc14_logo-1-300x104.jpg?resize=300%2C104\" alt=\"\" width=\"300\" height=\"104\" srcset=\"https:\/\/i0.wp.com\/raheelyawar.com\/wp-content\/uploads\/2017\/10\/gdc14_logo-1.jpg?resize=300%2C104 300w, https:\/\/i0.wp.com\/raheelyawar.com\/wp-content\/uploads\/2017\/10\/gdc14_logo-1.jpg?w=602 602w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>I&#8217;ve been working on the Unity game engine for more than a year now and this year I happened to attend GDC 2014. Here is what I gathered from a combination of sessions and from my own experiences. If you&#8217;re a Unity developer here are some tips that might come in handy or will reaffirm your faith if you already know them:<\/p>\n<p><b>On Game Testing<\/b><\/p>\n<p>Always test your application on the latest devices. Never test on jailbroken devices because their behaviour may vary from the regular devices which might skip a problem or reveal one specific to a device.<\/p>\n<div data-blogger-escaped-style=\"text-align: left;\"><\/div>\n<div data-blogger-escaped-style=\"text-align: left;\">\n<p>If you&#8217;re working on the iOS platform keep in mind that the iPods touch&#8217;s specs are always one step behind its current generation which means that the 5th generation iPod will not give you the same performance as the 5th generation iPhone. In short, iPods are not a non-cellular version of the iPhone and their memory and GPU performance is always too low compared to the screen size. Just a heads-up though, if you ever consider knocking iPods off your list of supported devices, iPod 4 was one of the most sold iOS devices.<\/p>\n<\/div>\n<p><b>Profiling and Optimization<\/b><\/p>\n<p>Use the profiler throughout the during of your project. Profiling and optimization should not come as an iteration once everything is done. I can relate to this point from my personal projects as well. If optimizations are pushed back until the end, they will add unnecessary development time.<\/p>\n<p>While working on\u00a0<a class=\"pagelink\" href=\"http:\/\/werplay.com\/runsheedarun\/\">Run Sheeda Run<\/a>, we had already decided how and which textures will be divided into atlases but we still used individual textures which took more than a day of artist&#8217;s time. On the other hand, the GUI textures were all bundled into atlases because NGUI dictates it which prevented us from making the same mistake we made with the rest of the game assets. Once you&#8217;re done prototyping, it&#8217;s probably a good idea to start putting your textures into atlases.<\/p>\n<p>Unity profiler makes a build unplayable which is why developers avoid it until completely necessary. If you&#8217;re working on the iOS platform, this is where the XCode&#8217;s profiler comes in. It gives you the basic statistics which include CPU and memory usage, along with the FPS.<\/p>\n<p><b>Best Memory Practices in Unity<img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignright wp-image-150 size-thumbnail\" src=\"https:\/\/i0.wp.com\/159.89.19.162\/wp-content\/uploads\/2017\/10\/unity-logo-1-150x150.png?resize=150%2C150\" alt=\"\" width=\"150\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/raheelyawar.com\/wp-content\/uploads\/2017\/10\/unity-logo-1.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/raheelyawar.com\/wp-content\/uploads\/2017\/10\/unity-logo-1.png?resize=300%2C300 300w, https:\/\/i0.wp.com\/raheelyawar.com\/wp-content\/uploads\/2017\/10\/unity-logo-1.png?resize=100%2C100 100w, https:\/\/i0.wp.com\/raheelyawar.com\/wp-content\/uploads\/2017\/10\/unity-logo-1.png?w=450 450w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/b><\/p>\n<p>Use the\u00a0<i>Resources.Load<\/i>\u00a0feature for assets there is used very rarely in the game. This does make the code slightly complicated because of its always easier to drag and drop prefabs in the scene but on mobile devices, its worth the effort. Don&#8217;t forget to pair it up with\u00a0<i>Resources.UnloadAsset<\/i>\u00a0or\u00a0<i>Resources.UnloadUnusedAssets<\/i>\u00a0as needed.<\/p>\n<p><b>Best Lighting Practices in Unity<\/b><\/p>\n<p>If flat shading is not going to work for you in a particular project, a lot of visually appealing games make use of light probes, which fake real-time lighting. Lightmaps are baked into the textures and use virtually zero memory.<\/p>\n<p><b>Asynchronous Load Screen<\/b><\/p>\n<p>Until very recently, I thought that Unity only provides only a single way to load a new scene (Application.LoadLevel) and that you cannot display an animated loading screen. This might have been extremely obvious but if you didn&#8217;t know Application.LoadLevelAsync lets your load a scene asynchronously. Which means that you can display a progress bar or an animation while the game loads.<\/p>\n<p><b>Multiple Screen Sizes<\/b><\/p>\n<p><a href=\"https:\/\/images-blogger-opensocial.googleusercontent.com\/gadgets\/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-GFd1p4c_0gM%2FU1PB0nQ5vpI%2FAAAAAAAABZw%2FXzhD7NUR4p0%2Fs1600%2Flogo_big.png&amp;container=blogger&amp;gadget=a&amp;rewriteMime=image%2F*\" data-blogger-escaped-style=\"clear: right; float: right; margin-bottom: 1em; margin-left: 1em;\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignright\" src=\"https:\/\/i0.wp.com\/1.bp.blogspot.com\/-GFd1p4c_0gM\/U1PB0nQ5vpI\/AAAAAAAABZw\/XzhD7NUR4p0\/s1600\/logo_big.png?resize=200%2C200&#038;ssl=1\" width=\"200\" height=\"200\" border=\"0\" \/><\/a>There are too many devices with varying screen resolutions out there, even if you&#8217;re working on the iOS platform. It&#8217;s best you&#8217;re already prepared for it before you start working on a project. Fortunately, Unity makes it really easy to calculate the aspect ratio of a device and according to that you can adjust your UI components.\u00a0How to determine screen size using DPI\u00a0is a blog post by a colleague at\u00a0<a class=\"pagelink\" href=\"http:\/\/werplay.com\/\">we.R.play<\/a>\u00a0that provides a code snippet that will in handy.<\/p>\n<p><b>Building for Windows Phone<\/b><\/p>\n<ul>\n<li>When building for a windows phone device, Unity first creates a Visual Studio project. The native code of the application is stored in App.xaml.cs file.<\/li>\n<li>Unlike iOS and Android, Visual Studio&#8217;s simulator is supported for Unity applications.<\/li>\n<li>Additionally, unlike iOS and Android, the application icons need to be manually added to the Visual Studio project.<\/li>\n<li>If you&#8217;re too used to working with the Visual Studio IDE, good news for you, it can be used with Unity as a replacement of MonoDevelop.<\/li>\n<li>If you are making use of custom shaders, it&#8217;s a good idea to test with the different versions of DirectX to be sure that the shaders&#8217; behaviour is as intended.<\/li>\n<\/ul>\n<p><b>Citation:<\/b><\/p>\n<p>Apart from my own and my colleague&#8217;s experiences at we.R.play, this post contains a lot of tips I learnt from the following GDC 2014 sessions:<\/p>\n<ul>\n<li>\u00a0iOS Games in a Day by Gareth Jenkins<\/li>\n<li>Your Unity Game in More Hands presented by Microsoft<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working on the Unity game engine for more than a year now and this year I happened to attend GDC 2014. Here is what I gathered from a combination of sessions and from my own experiences. If you&#8217;re a Unity developer here are some tips that might come in handy or will reaffirm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"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":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2,4],"tags":[6,8,9],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-game-development","category-portfolio","tag-game-development","tag-unity","tag-unity3d"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9NqGD-2o","_links":{"self":[{"href":"http:\/\/raheelyawar.com\/index.php?rest_route=\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/raheelyawar.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/raheelyawar.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/raheelyawar.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/raheelyawar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=148"}],"version-history":[{"count":0,"href":"http:\/\/raheelyawar.com\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions"}],"wp:attachment":[{"href":"http:\/\/raheelyawar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/raheelyawar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/raheelyawar.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}