in Game Dev+Unity

Unity Engine Tips & Best Practices – Mobile Games

I’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’re a Unity developer here are some tips that might come in handy or will reaffirm your faith if you already know them:

On Game Testing

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.

If you’re working on the iOS platform keep in mind that the iPods touch’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.

Profiling and Optimization

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.

While working on Run Sheeda Run, 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’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’re done prototyping, it’s probably a good idea to start putting your textures into atlases.

Unity profiler makes a build unplayable which is why developers avoid it until completely necessary. If you’re working on the iOS platform, this is where the XCode’s profiler comes in. It gives you the basic statistics which include CPU and memory usage, along with the FPS.

Best Memory Practices in Unity

Use the Resources.Load feature 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’t forget to pair it up with Resources.UnloadAsset or Resources.UnloadUnusedAssets as needed.

Best Lighting Practices in Unity

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.

Asynchronous Load Screen

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’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.

Multiple Screen Sizes

There are too many devices with varying screen resolutions out there, even if you’re working on the iOS platform. It’s best you’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. How to determine screen size using DPI is a blog post by a colleague at we.R.play that provides a code snippet that will in handy.

Building for Windows Phone

  • 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.
  • Unlike iOS and Android, Visual Studio’s simulator is supported for Unity applications.
  • Additionally, unlike iOS and Android, the application icons need to be manually added to the Visual Studio project.
  • If you’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.
  • If you are making use of custom shaders, it’s a good idea to test with the different versions of DirectX to be sure that the shaders’ behaviour is as intended.

Citation:

Apart from my own and my colleague’s experiences at we.R.play, this post contains a lot of tips I learnt from the following GDC 2014 sessions:

  •  iOS Games in a Day by Gareth Jenkins
  • Your Unity Game in More Hands presented by Microsoft
Share
Share this Post
Your URL copied
Comments on This Post
Let us know your thoughts about this topic

Your email address will not be published. Required fields are marked *

Top