August 03 2020
By Rubén Torres Bonet
August 03, 2020
Let’s talk about the concept of frame pacing to learn how to reduce the performance stutters that your game suffers.
If you want smoother gameplay in your Android games, then this post is for you.
Your game renders at 60 FPS, so there is no reason to worry about performance, right?
You see, Frames Per Second (FPS) is just an average.
Let’s say you and I go to a restaurant. Each of us order a burger…
But I am hungry and greedy. So I eat them both. I leave you with zero burgers 🙂
That’s ok for you, right? After all, in average, we ate one burger each.
That’s a mathematically true statement, but I bet that wouldn’t make you any happier.
So that’s exactly how the FPS metric can deceive you… by trusting averages.
In just 1 second, you can manage to render:
- VERY fast frames
- And also VERY slow frames
In other words: an uneven frame pace.
And yet… Your FPS counter can happily show you 60 FPS.
But you wouldn’t deserve it.
Why is that?
A game stutters when its rendering speed is inconsistent and its frames are presented at varying rates in the screen.
A typical user will see some type of short of micropauses that annoy the hell out of them and possibly cause them to rage.
This perceived gameplay instability (stuttering) happens because some frames stay longer in your monitor than others… for the simple reason these frames are not available for when the screen demands.
Now, you might think v-sync can help you here… as it is always enabled on Android.
But nope. V-sync doesn’t help with performance stutters…
V-sync only helps with screen tearing.
Two different things.
No matter what, it’s hard to lie to our eyes in the area of game performance.
Here’s an example of input latency. Can you spot it?
Ideally, you have to destroy both performance stutters and screen tearing.
And here’s how:
Sounds good in theory…
But in real-life, you’ll always have troublesome situations. And you won’t like them.
Engineers know this.
That’s why we have solutions that reduce the ocular damage these performance problems cause to you and your fans.
And regarding game stutters, one of these solutions is Swappy for Android.
Let’s see how this weird name will help you.
I know, Swappy sounds like the name everyone would choose for a pet.
And it is a life savior!
Swappy is the frame pacing library that will help you achieve smoother rendering when you are in trouble.
Remember: frame pace is the speed (and consistency of speed) at which your game deliver its frames. And we want this pace to be even and consistent.
So, how does Swappy help?
You see, the operating system’s default behavior is to display the front-buffer in your screen. Aways.
And that’s fine when your game performs well… but when you have uneven frame pacing, then it’s not necessarily optimal.
You see, Swappy is smarter than that. This library chooses the best frame to display on your screen depending on how early — or how late— you are delivering your frames.
To improve the perceived frame-rate smoothness in these situations.
Swappy will choose to display either:
And it does so at the right time, i.e. when the screen is ready to display a new frame.
The mechanism behind this is relatively simple on the surface.
I’ll describe how Swappy works in a future post. In the meantime, you can give it a read here.
This library is designed to take advantage of the different refresh rates of your Android devices. Some mobile screens support 90 Hz and beyond nowadays.
And varying screen refresh rates help you achieve smoother gameplay as well.
Ok, let’s cut the chase. Can you use Swappy in Unity?
You bet you can.
And it’s stupidly easy on Unity 2019.2+.
It’s as simple as enabling “Optimized Frame Pacing” on the Android player settings.
As always, test this setting before deploying it to production.
See how it feels for you and other users.
Remember, you should aim to deliver consistent frame-rates to prevent stutters from ruining your players’ experience (and your wallet).
Here’s an example of an angry user…
You don’t want that to happen in your project.
If you want me to personally help you achieve higher frame-rates in your game, send me an email to email@example.com and we’ll get it sorted.