Reader small image

You're reading from  Unity Game Optimization - Third Edition

Product typeBook
Published inNov 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781838556518
Edition3rd Edition
Languages
Tools
Right arrow
Authors (2):
Dr. Davide Aversa
Dr. Davide Aversa
author image
Dr. Davide Aversa

Dr. Davide Aversa holds a PhD in Artificial Intelligence (AI) and an MSc in AI and robotics from the University of Rome La Sapienza in Italy. He has a strong interest in AI for the development of interactive virtual agents and procedural content generation. He has served as a program committee member for video game-related conferences such as the IEEE conference on computational intelligence and games, and he also regularly participates in game-jam contests. He also writes a blog on game design and game development.
Read more about Dr. Davide Aversa

Chris Dickinson
Chris Dickinson
author image
Chris Dickinson

Chris Dickinson grew up in a quiet little corner of England with a strong passion for mathematics, science and, in particular, video games. He loved playing them, dissecting their gameplay, and trying to figure out how they worked. Watching his dad hack the hex code of a PC game to get around the early days of copy protection completely blew his mind! His passion for science won the battle at the time; however, after completing a master's degree in physics with electronics, he flew out to California to work in the field of scientific research in the heart of Silicon Valley. Shortly afterward, he had to admit to himself that research work was an unsuitable career path for his temperament. After firing resumes in all directions, he landed a job that finally set him on the correct course in the field of software engineering (this is not uncommon for physics grads, I hear). His time working as an automated tools developer for IPBX phone systems fit his temperament much better. Now he was figuring out complex chains of devices, helping its developers fix and improve them, and building tools of his own. Chris learned a lot about how to work with big, complex, real-time, event-based, user-input driven state machines (sounds familiar?). Being mostly self-taught at this point, Chris's passion for video games was flaring up again, pushing him to really figure out how video games were built. Once he felt confident enough, he returned to school for a bachelor's degree in game and simulation programming. By the time he was done, he was already hacking together his own (albeit rudimentary) game engines in C++ and regularly making use of those skills during his day job. However, if you want to build games, you should just build games, and not game engines. So, Chris picked his favorite publically available game engine at the time--an excellent little tool called Unity 3D--and started hammering out some games. After a brief stint of indie game development, Chris regretfully decided that the demands of that particular career path weren't for him, but the amount of knowledge he had accumulated in just a few short years was impressive by most standards, and he loved to make use of it in ways that enabled other developers with their creations. Since then, Chris has authored a tutorial book on game physics (Learning Game Physics with Bullet Physics and OpenGL, Packt Publishing) and two editions of a Unity performance optimization book (which you are currently reading). He has married the love of his life, Jamie, and works with some of the coolest modern technology as a software development engineer in Test (SDET) at Jaunt Inc. in San Mateo, CA, a Virtual Reality/Augmented Reality startup that focuses on delivering VR and AR experiences, such as 360 videos (and more!). Outside of work, Chris continues to fight an addiction to board games (particularly Battlestar: Galactica and Blood Rage), an obsession with Blizzard's Overwatch and Starcraft II, cater to the ever-growing list of demands from a pair of grumpy yet adorable cats, and gazing forlornly at the latest versions of Unity with a bunch of game ideas floating around on paper. Someday soon, when the time is right (and when he stops slacking off), his plans may come to fruition
Read more about Chris Dickinson

View More author details
Right arrow

Optimizing Your Art Assets

Art is a famously subjective discipline, dominated by personal opinion and preference. It can be challenging to say whether, and why, one piece of art is better than another. Oftentimes, our opinions won't be able to find a complete consensus. The technical aspects behind art assets that support a game's artistry can also be very subjective. Multiple workarounds can be implemented to improve performance, but these tend to result in a loss of quality for the sake of speed. If we're trying to reach peak performance, then we must consult with our team members whenever we decide to make any changes to our art assets, as it is primarily a balancing act, which can be an art form in itself.

Whether we're trying to minimize our runtime memory footprint, keep the smallest possible executable size, maximize loading speed, or maintain consistency...

Audio

As a framework, Unity can be used to build anything from small applications that require only a handful of sound effects and a single background track to huge role-playing games that need millions of lines of spoken dialog, music tracks, and ambient sound effects. Regardless of the actual scope of the application, audio files are often a significant contributor to the application size after it is built (sometimes called its disk footprint). Moreover, many developers are surprised to find that runtime audio processing can turn into a significant source of CPU and memory consumption.

Audio is often neglected on both sides of the gaming industry: developers tend not to commit many resources to it until the last minute and users rarely pay attention to it. Nobody notices when audio is handled well, but we all know what lousy audio sounds like—it's instantly recognizable...

Texture files

The terms texture and sprite often get confused in game development, so it's worth making the distinction: a texture is simply an image file, a big list of color data telling the interpreting program what color each pixel of the image should be, whereas a sprite can be seen as the 2D equivalent of a mesh—it defines how and where the image will appear in the game scene. Usually, a sprite is just a single quad (a pair of triangles combined to make a rectangular mesh) that renders flat against the current camera.

There are also things called sprite sheets, which are large collections of individual images contained within a larger texture file, commonly used to contain the animations of a 2D character. These files can be split apart by tools, such as Unity's Sprite Atlas tool, to form individual textures for the character's animated frames.

Of course...

Mesh and animation files

The mesh and animation file types are essentially large arrays of vertex and skinned bone data, and there are a variety of techniques we can apply to minimize file size while keeping similar, if not identical, appearances. There are also ways to lower the cost of rendering large groups of these objects through batching techniques. Let's take a look at a series of performance-enhancing techniques that we can apply to such files.

Reducing the polygon count

Reducing the polygon count is the most obvious way to gain performance and should always be considered. In fact, since we cannot batch objects using skinned mesh renderers, it's one of the good ways of reducing CPU and GPU runtime overhead...

Asset bundles and resources

We touched upon the topic of resources and serialization in Chapter 2, Scripting Strategies, and it should be fairly clear that the resource system can be a great benefit during prototyping, as well as during the early stages of our project, and can be used relatively effectively in games of limited scope.

However, professional Unity projects should instead favor the asset bundle system. There are a number of reasons for this. Firstly, the resource system is not very scalable when it comes to builds. All resources are merged together into a single massive serialized file binary data blob with an index list of where various assets can be found within it. This can be hard to manage, and take a long time to build as we add more data to the list.

Secondly, the resource system's ability to acquire data from the serialized file scales in an Nlog(N)...

Summary

There are many different opportunities that we can explore to achieve performance gains for our application just by tinkering with our imported assets. Alternatively, from another perspective, there are plenty of ways to ruin our application's performance through asset mismanagement. Almost every single import configuration opportunity is a trade-off between one performance metric or workflow task and another. Typically, this means saving the disk footprint via compression at the expense of CPU at runtime to decompress the data, or faster access while reducing the quality level of the final presentation. So we must remain vigilant and only pick the right techniques for the right assets for the right reasons.

This concludes our exploration of improving performance through art asset manipulation. In the next chapter, we will be investigating how to improve our usage...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Unity Game Optimization - Third Edition
Published in: Nov 2019Publisher: PacktISBN-13: 9781838556518
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Dr. Davide Aversa

Dr. Davide Aversa holds a PhD in Artificial Intelligence (AI) and an MSc in AI and robotics from the University of Rome La Sapienza in Italy. He has a strong interest in AI for the development of interactive virtual agents and procedural content generation. He has served as a program committee member for video game-related conferences such as the IEEE conference on computational intelligence and games, and he also regularly participates in game-jam contests. He also writes a blog on game design and game development.
Read more about Dr. Davide Aversa

author image
Chris Dickinson

Chris Dickinson grew up in a quiet little corner of England with a strong passion for mathematics, science and, in particular, video games. He loved playing them, dissecting their gameplay, and trying to figure out how they worked. Watching his dad hack the hex code of a PC game to get around the early days of copy protection completely blew his mind! His passion for science won the battle at the time; however, after completing a master's degree in physics with electronics, he flew out to California to work in the field of scientific research in the heart of Silicon Valley. Shortly afterward, he had to admit to himself that research work was an unsuitable career path for his temperament. After firing resumes in all directions, he landed a job that finally set him on the correct course in the field of software engineering (this is not uncommon for physics grads, I hear). His time working as an automated tools developer for IPBX phone systems fit his temperament much better. Now he was figuring out complex chains of devices, helping its developers fix and improve them, and building tools of his own. Chris learned a lot about how to work with big, complex, real-time, event-based, user-input driven state machines (sounds familiar?). Being mostly self-taught at this point, Chris's passion for video games was flaring up again, pushing him to really figure out how video games were built. Once he felt confident enough, he returned to school for a bachelor's degree in game and simulation programming. By the time he was done, he was already hacking together his own (albeit rudimentary) game engines in C++ and regularly making use of those skills during his day job. However, if you want to build games, you should just build games, and not game engines. So, Chris picked his favorite publically available game engine at the time--an excellent little tool called Unity 3D--and started hammering out some games. After a brief stint of indie game development, Chris regretfully decided that the demands of that particular career path weren't for him, but the amount of knowledge he had accumulated in just a few short years was impressive by most standards, and he loved to make use of it in ways that enabled other developers with their creations. Since then, Chris has authored a tutorial book on game physics (Learning Game Physics with Bullet Physics and OpenGL, Packt Publishing) and two editions of a Unity performance optimization book (which you are currently reading). He has married the love of his life, Jamie, and works with some of the coolest modern technology as a software development engineer in Test (SDET) at Jaunt Inc. in San Mateo, CA, a Virtual Reality/Augmented Reality startup that focuses on delivering VR and AR experiences, such as 360 videos (and more!). Outside of work, Chris continues to fight an addiction to board games (particularly Battlestar: Galactica and Blood Rage), an obsession with Blizzard's Overwatch and Starcraft II, cater to the ever-growing list of demands from a pair of grumpy yet adorable cats, and gazing forlornly at the latest versions of Unity with a bunch of game ideas floating around on paper. Someday soon, when the time is right (and when he stops slacking off), his plans may come to fruition
Read more about Chris Dickinson