Unity Optimization Tips

Unity Optimization Tips

Are you planning to optimize your game made with Unity and get the best performance? In this Complete Unity Optimization Guide, I will show you how to increase performance in Unity correctly, so your game will run fast & stable.

Here I will consider optimization tools provided by?Unity Game Engine?and also by Indie Developers (Publishers) in?Unity Asset Store?— Top Unity Assets (Tools) for

Unity Optimization


1 Main Optimization Cycle in Unity
2 Types of Performance Issues
2.1 Spikes
2.2 Every-frame costs
2.3 Loading Time
2.4 Memory Usage        

Main Optimization Cycle in Unity

Unity Optimization refers to the process of making your game run better. Usually, the main reason for optimization is to make the gameplay smoother or to make the game more available to a wider audience so the game runs better on lower-end devices.

No alt text provided for this image

  1. If your game works without lags and freezes on target platforms, then the game does not need to be optimized. Do more important things like new levels in the current game.

Optimization for the sake of optimization is a waste of time.

  • If you have lags and freezes then the starting point is Profiling (firstly with?Unity Profiler) to detect what kind of performance issues Unity Project has.
  • After the optimization tasks have been determined and before the process of optimization is started, it is advisable to take some time and consider which area of optimization is the priority. This is done by comparing the approximated time each specific implementation?of optimization would take and a performance gain in the result.
  • The resulting ordered list of optimization tasks will work as a guideline for the entire process of optimization starting with the most effective action. This also helps to gain the most performance with the least effort. Follow this list until the game on target platforms has smooth gameplay and a stable frame rate.
  • If the game is executing excellently without visible problems and the list of optimization tasks is not empty then forget further optimization process.
  • If the game still has problems then the project should be profiled and the data stored. Next stored data can be compared with previous data allowing for a closer inspection of the state of the whole optimization process.
  • Repeated profiling allows you to understand what happened after the completion of a single optimization task, whether this procedure brought a performance improvement or not.

Types of Performance Issues

  • You can Optimize Unity Game in different ways depending on the problem's nature. Performance problems can be divided into several types depending on their nature.
  • Spikes
  • Spike is a sudden drop in the frame rate of a game. This is noticed when a game suddenly stops and doesn’t move for a noticeable time. This can break the immersion of the player or cause him to make a mistake he wouldn’t have otherwise made. Spikes can be seen as a high point on Profiler Graph.

No alt text provided for this image

Spikes are mainly caused by complex calculations or difficult operations performed during a single frame. Annoying Spikes are a problem in high-intensity games which need a stable frame rate and high control over the game to feel good, such as?driving?or?shooting games?(FPS).

No alt text provided for this image

Spikes of Garbage Collector

  • Garbage collection spikes are frame rate drops specifically caused by the garbage collection system of Unity. These can be huge frame rate spikes and are easily noticed while playing the game. The spikes happen when the memory garbage limits are met and the collection runs, cleaning up the unnecessary objects from the memory. Their frequency is mandated by how much garbage the game generates for each frame. The frequency can be slowed down by generating less garbage during runtime.
  • The only way of preventing these spikes completely is to generate no garbage during runtime. This is a huge undertaking and must be considered from the very beginning of a project.

Every-frame costs

  • Every-frame costs are the calculations and operations that are run every single frame. These can be, for example, physics calculations, running?AI behavior, or handling animations of characters.
  • Every-frame costs slow down the general frame rate of the game. They are the little things that slow the game down and make it feel less fluid. If a game just generally runs poorly, this is the area that needs work.

Loading Time

Loading time refers to how long the game takes to load. This includes the first load when the game is opened and loading that happens during runtime, for example between scenes.

While not usually a major issue, having extremely long loading times or having?loading screens?appear far too often can negatively affect the user experience.

To reduce the length of loading screens, consider splitting up the work done during them. This can mean preloading assets beforehand to reduce the number of objects that need to be loaded during the loading screen, or reducing the complexity of loaded scenes.

Open World

In an open-world game, where many objects need to be loaded during runtime, a method of recycling or streaming assets can be implemented. In the?“Inside” Game?a small part of every frame is dedicated to loading and unloading assets. This allows the whole four-hour experience to be played through with just a single initial loading screen.


Memory Usage

RAM (Random Access Memory) is the memory on which a game is loaded while running. RAM stores everything needed by a game during runtime.

VRAM (Video Random Access Memory) is on a graphics card and is intended for graphical effects. VRAM is the storage used to store textures and models drawn by the graphics card.

RAM is what your CPU uses, while VRAM is what your GPU uses. Either or both might become a bottleneck on a project running unoptimized or simply with far too many assets. When there is not enough memory, stuttering may occur.

To reduce the amount of memory needed by your project, consider next:

  • Reduce the complexity of objects and the resolution of textures;
  • Make fewer unique assets in the project;
  • Use?Object Pools.

Faheem Aaghar

Unity | AR | VR | TikTok Effect House |Snapchat lens studio Developer

2 年

Nice Job

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了