Unity 3D mobile game optimization presents a number of challenges, and we’ve done the legwork and made it really easy to solve them. The wide selection and variety of mobile devices combined with extremely diverse hardware and specifications are enough to give even the best of us a headache.  There are a number of resources available online to help better understand Unity 3D game optimization.

Gurjeet Matharu B.Sc – Lead Engineer
Disrupted Logic Interactive Inc.
ctalyst® Team

Please note that while we attempt to maintain information that is current and up to date, the 3rd parties described here may change their techniques, interfaces, policies and programs at any time and without notice. Please be sure to follow the links for further and up-to-date information.

 

 

Unity 3D and ctalyst

The ctalyst® engineering team at Disrupted Logic Interactive has put together this informative, brief guide on game optimization techniques to help get you started, tackle some of the bigger issues, and ensure your Unity 3D game will run great every time, even on older mobile devices.  This guide is based on our experiences with our new game Dead Corps 2 which can be downloaded free on iTunes and Google Play (apologies for the shameless plug).

The purpose of this guide is to provide you with a quick, hit-the-ground-running, start to optimizing your Unity games for better performance.  You can find more detailed information on Unity’s site at https://docs.unity3d.com/Manual/MobileOptimizationPracticalGuide.html

Unity 3D Game Optimization Memory

Image by: Victorrocha
Use: GNU Free Documentation License

Optimizing Memory

Unity 3D game optimization bottlenecks are ultimately the result of poor memory allocation and usage during development. It is Memory that will determine the frame rate (FPS aka Frames Per Second) of your game. The topic of memory optimization is far more complex and in-depth than the intended scope of this guide. But the basic concepts remain the same.  Most mobile devices lack the built-in memory to play games without at least a little bit of optimization on your part as a game developer.

Memory usage issues in Unity 3D game development are typically a problem of poor optimization and the inefficient use and application of resources within the game environment. By using some of the optimization techniques in this guide and setting up your game properly, memory demands will be drastically reduced and you’ll experience greater performance from your games and over a wider range of devices, including new and old.

After using the optimization techniques detailed in this guide, Disrupted Logic’s Dead Corps 2 was able to run flawlessly on iPad 2nd generation tablets and low-powered older Android tablets.

Unity 3D Game Project Organization – The First Step To Better Optimization

Unity 3D Game Optimization File Management

Image by: Alex Gorzen
Use: Creative Commons Attribution-Share Alike 2.0 Generic license

A poorly organized Unity 3D project will be extremely difficult to optimize and troubleshoot. And this doesn’t even start to mention the challenges faced when collaborating with your teammates.  Poor organization often leads to repeated materials and textures, unnecessary asset duplication, increased development time, and overall inefficiency.  All of which contribute to creating optimization and memory bottlenecks, along with bigger load and rendering demands on the mobile device.

Optimization is much easier if you define a project structure and stick to it.  Know where to find your materials and various assets, and give each of them meaningful names.  The difficulty of optimization is amplified when every item in your project is named “untitled_#”.

With our Dead Corps 2 project, we created project folders for Plugins, Materials, Models, Scenes, Menus, Textures and so on.  We then named each asset based on what it was or what it was being used for.

We found this great article, “On Structuring Things In Unity” by the folks at Big Robot on how they organize their Unity 3D game projects.

Unity 3D Lighting Performance Tips

Unity 3D game artists LOVE to work and play with lighting.  Nothing adds to the look and feel of a mobile game more than lighting.  And bless the good people at Unity for making lighting so incredibly easy to work with!

That said, nothing drives us nuttier than trying to optimize Unity 3D’s lighting for performance.  It drives both artists and programmers absolutely crazy.

The number one bottleneck for mobile platforms is the real-time rendering of lighting.  The creative folk at Disrupted Logic invested a great deal of time designing the lighting and look for Dead Corps 2.  And it looks great!  Lighting, as a technical choice though, can be both confusing and difficult. By simply baking your lighting, you will more than double your Unity game’s performance. Here are a few easy steps to help you accomplish this:

Make sure all your lights are Baked

Unity 3D Game Optimization Baked Lighting

Make sure that all objects receiving light are marked as Lightmap Static

Unity 3D Game Optimization Lightmap Static

Once you’ve configured your lighting, proceed to Window>Lighting menu item and select the Scene tab. Check the “Baked GI” box.

Unity 3D Game Optimization Lighting Baking

Select the Lightmaps tab and click Build to bake your lighting! Once you have baked your lighting you can disable the real-time lights in your game by unchecking all of the lights within your scene. Play test your game to see how it looks and performs.

Unity 3D Game Optimization Light Mapping

You might find that the resulting baked lighting is significantly different than you expected.  Don’t despair!  We freaked out when we thought we had the same problem with Dead Corps 2.

The problem is very easily fixed by adjusting the balance of the Ambient Light and Individual Light intensities until they match your visual expectations and then re-baking the scene.

Unity’s documentation provides a comprehensive and easy to understand description of how to optimize your lighting for greater performance.  You can find the documentation here: https://docs.unity3d.com/Manual/GlobalIllumination.html

 

 

Performance Boost Using Unity 3D’s Occlusion Culling

Unity 3D Game Optimization Occlusion CullingUnity 3D Personal Edition is now a fully feature-packed which includes Occlusion Culling!  You can download it FREE at the Unity Store.

Occlusion renders only those objects and items that appear in front of the camera.  In most basic terms, this means that objects, sets, lighting and any other items that are not immediately visible to the camera are not rendered until they’re actually needed.

This creates a massive optimization and performance boosting opportunity for developers and it’s as easy as flipping a switch and defining a mesh.

There is no need to have the CPU/GPU and RAM going crazy rendering and storing massive amounts of data that are not yet important to the player and won’t be needed for awhile.

Using Unity 3D’s “default” Occlusion Culling (Occlusion Areas) will immediately improve the performance of your game.  Should you fine-tune and adjust the mesh grid and areas to occlude, you’ll see an even bigger game performance boost!

It’s as easy as that!

Unity 3D Game Optimization Dead Corps 2Optimizing 3D Models For Performance

The 3D models you use in your game development will impact Unity 3D’s mobile performance.  Here is a great article on Vertices and Polygons: http://blog.digitaltutors.com/whats-the-difference-a-comparison-of-modeling-for-games-and-modeling-for-movies/

Models and their associated textures and animations need to be rendered during gameplay experience. The number of vertices and polygons that make up each model will have a heavy impact on the game’s performance.

When we created Dead Corps 2, the Disrupted Logic creative team selected 9 different models, each ranging from 15 to 25 MB in their original pre-game optimization size.  They looked GREAT!  But at 25 MB, a single model is bigger than most mobile games in total.

Many artists will rightfully insist on the highest number of vertices and polys possible to “ensure quality”.  However, both you and your creative team might be surprised at how far you can reduce the vertice and poly count of your models without noticeably sacrificing quality at all.

Mixamos “Decimator” https://www.mixamo.com/decimator (free to use at the time of this writing) offers some great features designed to reduce model poly count and to help you optimize your models for maximum game performance. Our models dropped from 25MB to less than 1MB each.  Be sure to “decimate” your models to be optimized to both your platform and development targets.  And remember, you don’t always need high poly counts to make your beautiful game look great!

Unity 3D Image Optimization

Unity 3D image optimization is done through the Inspector. For the majority of mobile games, your textures and images most likely do not need to be larger than 256×256 pixels. Anything larger risks excessive CPU/GPU performance hits.  Images that are used as text or for important visual graphics such as UI elements can be safely created and implemented at 512×512 or 1024×1024.  It’s best to produce the images as “square” in order to minimize the impact on the processors.

In Disrupted Logic’s Dead Corps 2, we found that our text and UI Elements for mobile looked crisp and sharp at 512×512.

To optimize and image for highest performance, simply click an image or texture from within the project window. From the Inspector’s Import Settings, choose each target device, iOS or Android, check the Override box and then change the Max Size to 256.

Remember that to optimize your games for mobile, the key is to limit the “bit” count. Unity 3D likes images that are square: 1024×1024, 512×512, 256×256 and so on. Non-square images require more resources to process and render.

Unity 3D Game Optimization Image Optimization

Quite often, developers will be using duplicated images without really knowing they doing so.  Removing duplicated images and decals will make a noticeable difference in your game’s performance.  This is where properly organizing your project will be helpful (see the above section on Organization).

Performance Optimizing Shadows in Unity 3D

Disable real-time shadows, or any sort of real-time lighting computations.  Anything real-time must be computed by the mobile device’s CPU first before rendering and this will negatively impact your game’s performance!

Bake the shadows instead.  While real-time shadows that interact with characters are impressive, the performance impact may not be worth the effect for the gamer.

This is especially important if you would like to reach the widest possible audiences by supporting the billions of older devices that are out there.

Make All Game Objects “Static” To Take Advantage Of Unity 3D’s Inbuilt Optimization

Ensure all your game objects are accurately labeled as static.  By skipping this step you are not using Unity’s inbuilt optimization and your game performance will take a hit.

Unity 3D Game Optimization Lightmap Static

Unity 3D Materials Optimization

Unity 3D Game Optimization Generate Mips MapCareless handling of Materials will also negatively impact your game.  A good practice is to start by minimizing the number of materials you’ll be using altogether.  Use just one material with many different objects, and use a mesh filter to separate each piece.

A clear example is with UI related images.  In Dead Corps 2, we created one large 1024×1024 image with each UI element on it and then applied a mesh filter to retrieve each individual piece from the image.

Additionally, be sure your materials are using the mobile diffuser, and are optimized (as described above in the Image section) for the native platform you will be publishing to.

Enable mipmaps for objects that are rendered and do not need to be super crisp and clear.  This is a great game optimization option for Unity 3D objects and Unity 3D prop textures, as well as various in-game textures such as walls, doors and so on. However, this is not a satisfactory option for UI or menu elements.

Minimize the size of textures you are using and preferably use 16-bit.

Optimizing Your Unity 3D Scripts

Avoid the use heavy mathematical operations and computations, and stay away from float operations.  Be conscious of the data structures you use, and their space and time complexity.  This is a complex topic to understand, and because of its highly technical nature it should not be an issue for most Unity 3D game or app developers.  However, it’s still something to be aware of.

Here’s a quick and easy cheat sheet that explains it better:  http://bigocheatsheet.com

Unity 3D’s Profiler For Better Performance And Optimization

Unity 3D’s Profiler is your best friend!  It is an excellent tool for determining resource use and allocations.

Familiarize yourself with the Unity 3D Profiler and what each graphing item means and refers to.  The Profiler will show spikes in memory usage and CPU time.  By analyzing the spikes and anomalies, you’ll be able to identify underlying issues, fix them and then visually observe the difference in optimized performance.

Unity 3D Game Optimization The Profiler

After running these 10 easy optimization techniques for your Unity 3D mobile games, you should see huge improvements in your game’s performance.  If you do not see a clear and noticeable difference, go back and ensure you have properly configured everything.  Remaining spikes and performance hits are usually an indication that you’ve missed or overlooked something. Don’t be afraid to go back again and again until you get the results you need.

Feel free to reach out to us at Disrupted Logic Interactive and ctalyst®.  We’re always excited and happy to work with developers and help them get the most out of their apps and games.

 

 

Please leave a comment below with your performance and optimization tips and tricks.

 

Be sure to share the love!