Join Jesse Freeman for an in-depth discussion in this video Using the profiler, part of Unity 5 2D: Optimizing Graphics.
- View Offline
- Here we have a tile map game object and if we look inside, you'll see that we have over 200 game objects representing each of the tiles in the map. If we select a tile, you'll see that it's just a game object with a sprite render and an image. Now, one of the ways that we can gage the performance of our scene is by using the Profiler. You can find the Profiler in the 'Window' menu. I like to put the Profiler at the bottom of the screen, so I can see the most amount of data possible while I'm testing. Inside of the Profiler, you'll see categories that best represent the performance of different aspects of your game.
CPU Usage, Rendering, Memory, Audio, Physics, as well as a separate area for Physics (2D) and then Networking. Let's scroll up to the top of the CPU Usage and run the game and see what happens. As you play it, data will begin to populate inside of the Profiler screen. If you select inside of an area of the Profiler, it'll pause and show you more detail about that particular section. Let's take a look at one of these spikes. As we can see, the largest spike is actually coming from Vsync.
Vsync is what synchronizes the refresh rate of the display to avoid tearing in artifacts. This can be changed as part of the quality settings for your game. Some games it doesn't make sense to have Vsync on. We can take a look at what our game's performance would be like without Vsync by clicking on the color next to it's name. As you can see, the next largest chunk of our CPU Usage is going to be the Rendering. The last part is a miscellaneous group called 'Other'. Everything else seems to be in line. That's because we're not using a lot of Physics and we don't have any heavy scripting.
Now, I'm going to re enable Vsync and run the game. Right now the Profiler is stuck at the position we had selected before. If you hit the 'Current' button, you'll get a sampling from the latest frame. Now, if I was to select the Camera and change it's 'X' position you'll see we'll start getting a lot of spikes in our game. Let's pause this an take a look. Now in the beginning part, where the Profiler was sampling, it was still catching up to speed of where we were in the scene and what was going on. Now, once we started moving the camera position you'll see spikes in performance based on how much is going on in the scene.
So at this point, we've taken a look at how our scene is constructed, as well as how to use the Profiler and read data from the CPU Usage.