Simple Battery-life and Energy Optimization for Mobile Games using Unity
Are you creating a new mobile game using the Unity engine and your mobile-phone is getting really hot after playing for a while? Have your players complained about the app is draining their batteries?
If you answer yes on one of the above questions or you are just interested in a simple way to optimize battery-life for Unity games, then this guide is for you.
Frame rate is the key
I had the same problem when I first started developing Labyrinth Robots. My friends that tested the first alpha version of the app told me "the app was sucking the life out of their mobile". So I understood that it was very important to do something about it.
The simplest and most effective thing I found was clamping the frame rate. I put the maximum frame rate to 60 fps (frames per second), which was enough to have smooth movement and animations while still not turning the phone into a heater. Then turning the fps down during parts where the game didn't need all the fps.
Since Labyrinth Robots is a casual problem solving game it contains parts where the screen will remain idle for a very long time while the player is thinking. This is perfect time to optimize and lower the fps to 15 fps during these times. There is simple no reason to let the game render a lot of frames if these frames will be the same anyway. This trick may not work for all game types, but it is very handy for casual games.
How to set frame rate in Unity
First of you need to change a setting found in Edit->Project Settings->Quality. Under the Other section you will find V sync Count. (Unity doc: Docs.unity3d.com)
V sync Count must be turned off.
Then you can set the maximum frame rate in code using Application.targetFrameRate. For example:
public class MyGameManagerClass : MonoBehaviour { void Awake() { Application.targetFrameRate = 60; } }
Using this technique I could drastically lower the battery consumption of Labyrinth Robots. I recommend testing with different frame rates to see what fits your game the most.
Hope this guide will help!
Hello! Thank you for this trick, it is very useful) Maybe you found some other tricks? I experienced with 2D Unity game, killing my full battery in 1 hour ((( For exapmle Angry Birds or Cut the rope lives for 3-4 hours without any phone heating. I even thought about other engines, because of Unity's energy consumption.
Hi! It mostly comes down to graphics settings. Take a look at the settings under Edit->Project Settings->Quality. Depending on your type of game you may not need all of the fancy rendering and can lower some settings.
Hope it helps!
Wow that's surprisingly simple. Thanks.