Game optimization is one of the major terms being tossed around everywhere by game developers and gamers! You might have heard it several times from a streamer, a game developer, or a friend obsessed with video games!
But what is it? Why is it important? And how does it work?
What is game optimization?
Game optimization is the act of making changes to the source code of a video game to make sure that it performs well on the devices that it is intended to be played on. One of the major goals of game optimization is to keep the frames rate high and consistent on the devices that are running the game.
Basically, game optimization is the answer to a single question: “How do we make a game run smoothly on the devices that we are targeting?”.
Why is game optimization important?
The answer is simple: The more optimized a game is, the more devices it can run on, and thus the more money the game can make!
It’s true that the hardware that runs video games is getting better every single year, but so is the complexity of the video games being made.
Many video game studios are pushing photo realism these days, but they also have to keep in mind that not all of their clients will be having the latest hardware tech ! This is where game optimization comes in!
Keeping a high and consistent frame rate is vital to the success of any video game ! Any drop in performance at a critical point in a video game can instantly ruin the experience of the gamer!
If a boss fight causes an FPS drop for example, then the players might have a hard time beating that boss, or enjoying the overall process of fighting them, and that will definitely reflect on the reviews of the game and the reputation of the developers.
That said, game optimization is one of the major key factors that decide whether a game is going to be a total failure or not, regardless of how good the game idea or the game mechanics are.
How does game optimization work?
There are 3 major steps that I usually follow whenever I want to optimize any part of a video game that I am working on !! First I start by identifying what the issue is, then I identify possible solutions and implement them, and lastly I double check if the solutions have made any significant improvements without breaking other parts of the game.
1- identify the problem first using profiling
Randomly trying to guess why there is an FPS drop is often a waste of time! Game developers have to first identify the exact cause of the performance drop, and then deal with it.
This is where the profiler comes in! A profiler is a tool that usually comes with most game engines.
The profiler can show you a lot of useful information about every single frame in the game, and about the overall performance of the game.
The profiler shows information like how much time a certain task is taking to complete, how much memory is being used at any given moment, how many draw calls are being done, and so much more!
So the first thing that the game developer generally does when optimizing a certain part of a video game is to run that part of the game through the profiler!
Using the data that the profiler provides, the game developers then identify the possible causes of the performance drop, and then start thinking of some possible solutions!
2- Implement a solution
There are a number of common optimization techniques that can usually be applied to fix a large number of performance issues. Here is a list of some of these techniques:
2.1- Reducing memory allocations
Garbage collection is the process of reclaiming the parts of memory that aren’t being used anymore.
This process however can cause an FPS drop since it can take a significant amount of time.
That said, one of the most common optimization techniques in video games is to reduce the need for garbage collection by making sure that the game doesn’t keep allocating and deallocating memory.
This is generally done by “reusing game objects and instances” instead of creating new ones. Object pooling is one of the techniques used to do that.
2.2- Reducing texture sizes for lower end PCs
You can think of textures as images that are wrapped around objects to give them their intended look. For example, you can think of a 3D rock in a video game as an object shaped like a rock, and wrapped with a paper that looks like the surface of a rock. That paper is a “texture” in a video game.
Reducing the size of this texture can help in improving the performance of the game! When video games give you different graphics options, one of the things that they change based on what option you pick is the textures size.
2.3- Level of Details [LODs]
Have you ever wondered how the 3D models in any video game are made and what are they made of?
Well, a 3D model is simply a number of triangles attached to each other. Each triangle is called a “Polygon”, and they make up most 3D game objects you see in a video game.
Objects that have a high number of polygons (aka poly count) usually look better and more detailed than objects that have lower poly counts. However, the higher the number of polygons in an object, the more time it takes to render that object on the screen.
This is where LODs come into play ! 3D modelers usually make multiple versions of the same game object, and each version has a different amount of polygons!
Game developers then take these different versions of the models, and decide which one to display based on how far the object is from the point of view of the player.
For example, if you are standing exactly in front of a tree in a video game, then the game displays the best version of that tree (the model with the highest level of detail).
But then if you move away, then the details are no longer useful anyway since you are far away. This is when the game switches to a different version of the same tree that has a lower number of polygons.
It can go up to the point where the game just displays a flat image of a tree when you are extremely far away from that tree.
Why is this done? Simply to reduce the number of polygons that need to be rendered on the screen at once, and thus optimizing the performance of the game.
2.4- Dividing the game into separate scenes
Dividing the game into different scenes is another way of reducing the number of things the hardware has to load and process in a single frame.
If you load the whole game into memory at the same time, then the hardware will have a hard time keeping up with all the tasks needed to run the game.
However, if the game divides itself into scenes that get loaded/unloaded based on where the player is, what they are doing and so on, then the hardware will have less things to worry about when running the game.
Sequential video games use this technique extensively. For example, every level in a 2D platformer can be its own scene, and then when you move between levels, you get a loading screen.
During the loading screen, the game switches from the scene of the previous level to the scene of the new level, and thus it doesn’t have to worry about rendering any part of the previous level anymore, just the new one.
2.5- Showing/hiding objects in scenes based on what is visible to the player
Hiding objects when they are not within the point of view of the player is also another optimization technique that can be useful in crowded game scenes.
As a rule of thumb in game development, “if you can’t see something on the screen, then it most probably doesn’t exist in the world anymore until you look back”
This isn’t always the case of course, but this can be useful when there are a lot of objects in the scene.
One common trick used for example is to stop the animation of the NPCs when the player isn’t looking at them!
Animating 3D models is a performance heavy task ! That said, game developers try their best to reduce the number of objects being animated on the screen, especially the animations that involve changing the polygons’ positions of the models.
As an example, let’s say that an NPC is walking by, when that NPC is no longer visible on the screen, it will keep moving, but its animation will freeze.
It keeps moving because the game wants you to think that the NPC is still updating their position just in case you look back to see where they are positioned now, but as long as you aren’t looking at it, that NPC will be a frozen object moving along a path.
Some developers completely hide the NPC but keep track of what position they should be in in case the player looks back at them!
The same thing goes for other game objects. For example if you go into a house, and certain parts of the outside world are not visible from that house, then the developers might choose to turn off these outside world objects while you are in the house.
By turn off I mean make them completely disappear.
2.6- Improving the code quality and using efficient algorithms
The last optimization technique that I want to mention here is the efficiency of the code and the algorithms being used.
This isn’t actually a “Technique”, but rather just a reminder that the quality of the code written to make the game has a huge effect on how good the game runs on the various target hardware.
Generally speaking, a lot of inefficient algorithms can slip through the code of even the biggest games ever made.
Why is that the case? It’s because of the time constraints given to the engineers that are building these games.
If a certain feature “has to be done in less than a week” for example, then the game developers will sometimes have to stop worrying about producing the most optimized code and instead worry about “getting the feature done no matter what”.
In these scenarios, bad code will make it to the source code of the game.
Once in a while, it is common for the software engineers to go back and optimize their algorithms to improve the performance of the game, especially the ones that are causing significant performance issues in the game
3- Finally, test if the optimization actually had an effect on the game or not !!
After identifying the cause of any performance issue, and making changes to fix it, testing needs to be done.
The development team usually goes back to the profiler to see whether their changes have made any impact on the performance of the game, and if it did, how significant was that impact?
The QA team can also help by keeping an eye on the frame rate of the game before and after the optimizations are done, and noticing the difference in the overall experience on lower end devices.
That wraps up the process that I follow whenever I want to optimize certain parts of any video game that I am working on.
If you would like to read more about game development, here are some articles that you can check out right now: