Conclusion

In this chapter, we have introduced some extra features and a range of approaches to improve game performance and collect performance data for analysis.

The first three recipes in this chapter provide some ideas for adding some extra features to your game (pausing, slow motion, and securing online games). The rest of the recipes in this chapter provide examples of how to investigate and improve the efficiency and performance of your game.

There's more...

Just as there are many components in a game, there are many parts of a game where processing bottlenecks may be found and need to be addressed to improve overall game performance. Some additional suggestions and further reference sources are now provided to provide a launching pad for your further exploration of the issues of optimization and performance, since such topics could take up a whole book rather than just one chapter.

Game audio optimization

Mobile devices have considerably less memory and processing resources than consoles, desktops, or even laptops, and often raise the biggest challenges when it comes to game audio. For example, the iPhone can only decompress one audio clip at a time, so a game may suffer processing spikes (that is, slow down game frame rate) due to audio decompression issues.

Paladin Studios recommend the following audio file compression strategies for mobile games:

  • Short Clips: Native (no compression)
  • Longer clips (or ones that loop): Compressed in memory
  • Music: Stream from disc
  • Files which consistently cause CPU spikes: Decompress on load

For more information about this topic, see the following:

Physics engine optimization

For some strategies relating to physics, you might consider to improve performance the following:

  • If possible, use geometric primitive colliders (2D box/2D circle/3D box/3D sphere/3D cylinder):
    • You can have multiple primitive colliders
  • You can also have primitive colliders on child objects:
    • As long as you have a rigid body on the root object in the object hierarchy
  • Avoid 2D polygon and 3D mesh colliders:
    • These are much more processor intensive
  • Try increasing the delay between each FixedUpdate() method call to reduce physics:
    • Although not to the point where user experience or game behavior is below acceptable quality!
  • Wherever possible, start off rigid bodies in sleep mode (so that they don't require physics processing until woken up by code or a collision). See the following Unity script reference pages for making objects go to sleep and wake up:
    Physics engine optimization

More tips for improving script efficiency

Some code strategies you might consider to improve performance include the following:

  • Use Structs rather than Classes to improve speed up processing.
  • Wherever possible, use simple arrays of primitive types rather than ArrayLists, Dictionaries, or more complex collection classes. A good article about choosing the most appropriate collection in Unity can be found at http://wiki.unity3d.com/index.php/Choosing_the_right_collection_type.
  • Raycasting is slow, so avoid performing it every frame, for example, use coroutines to only raycast every 3rd or 10th frame.
  • Finding objects is slow, so avoid finding objects in Update() or inner loops, and you can have objects set up a public static variable to allow quick instance retrieval, rather than using a Find(…) method. Or you could use the Singleton design pattern.
  • Avoid using OnGUI(), since it is called every frame just like Update(); this is much easier to avoid now with the new Unity 5 UI system.

Sources of more wisdom about optimization

Here are several other sources that you might want to explore to learn more about game optimization topics:

Published articles that discuss premature optimization

Here are several articles discussing Donald Knuth's famous quotation about premature optimization being "evil":

Sources of more about Game Managers and the State Pattern

Learn more about implementing the State Pattern and Game Managers in Unity from the following sites:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.198.83