Book Image

Hands-On Unity 2020 Game Development

By : Nicolas Alejandro Borromeo
Book Image

Hands-On Unity 2020 Game Development

By: Nicolas Alejandro Borromeo

Overview of this book

Over the years, the Unity game engine has extended its scope from just being about creating video games to building AR/VR experiences, complex simulations, real-time realistic rendering, films, and serious games for training and education. Its features for implementing gameplay, graphics, and customization using C# programming make Unity a comprehensive platform for developing professional-level, rich experiences. With this book, you'll be able to build impressive Unity projects in a step-by-step manner and apply your knowledge of Unity concepts to create a real-world game. Complete with hands-on tutorials and projects, this easy-to-follow guide will show you how to develop your first complete game using a variety of Unity tools. As you make progress, you'll learn how to make the most of the Unity Editor and create scripts using the C# programming language. This Unity game development book will then take you through integrating graphics, sound, and animations and manipulating physics to create impressive mechanics for your games. You'll also learn how to code a simple AI agent to challenge the user and use profiling tools to ensure that the code runs in a performant way. Finally, you'll get to grips with Unity's AR Foundation for creating AR experiences for 3D apps and games. By the end of this book, you'll have developed a complete game and will have built a solid foundation using Unity's tooling ecosystem to develop game projects of any scale.
Table of Contents (24 chapters)
Chapter 20: Building the Project

Optimizing memory

We discussed how to profile and optimize two pieces of hardware—the CPU and GPU—but there is another piece of hardware that plays a key role in our game—RAM. This is the place where we put all of our game's data. Games can be memory-intensive applications, and unlike several other applications, they are constantly executing code, so we need to be especially careful about that.

In this section, we will examine the following memory optimization concepts:

  • Memory allocation and the garbage collector
  • Using the Memory Profiler

Let's start discussing how memory allocation works and what role garbage collection plays here.

Memory allocation and the garbage collector

Each time we instantiate an object, we are allocating memory in RAM, and in a game, we will be allocating memory constantly. In other programming languages, aside from allocating the memory, you need to manually deallocate it, but C# has a garbage collector...