Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Frame-rate control on Android / extending battery life

Discussion in 'Android' started by Wrywulf, Oct 12, 2011.

  1. Wrywulf

    Wrywulf

    Joined:
    Oct 12, 2011
    Posts:
    3
    I have googled shamelessly for the answer to this question a while now, but I don't seem to be getting anywhere...

    Problem:
    I'm fiddling with a 2D puzzle-style game targeting Android devices and have succeeded in making a working demo. So far so good.

    However, the when running the game and "adb shell top", I notice the cpu usage on my Nexus S is around 70% and the device is getting rather hot, which is seriously bad business for the battery life.
    Checking the internal profiler stats, I notice that a lot of the time is spent on rendering and issuing draw calls. On top of that, it seems that the frame-rate is being maxed out at 55-60fps, which is possible because the cpu-present delay is very short. This delay is pretty much the only time period the CPU can rest. This is fine for an action game i guess, but not ideal for a puzzle game.
    So, I really want to let the CPU rest a lot(!) more, since it's not really required to do all this work - the scene is static ~90% of the time.

    Attempted solutions:
    Being a Unity newbie, I first started looking for a form of event-driven power-management in Unity mobile. Something like: letting the game loop thread sleep until some event (eg. touch, timer) wakes it up and lets it do its job. Perhaps even extending it with a form of wakelocks, similar to what the Android OS Power-management framework utilizes.
    I ruled this out pretty quickly, since this apparently breaks with the nature of Unity's update loops.

    Then I thought, there are two approaches:
    1. reduce the amount of draw calls and complexity of scene (I use a lot 2D toolkit sprites, textures with transparency) - this is a need to have anyway
    2. reduce the targeted framerate to perhaps ~30fps, thereby letting the CPU rest longer between frames.

    1. is more or less specific to my project and must be done. But I thought that Unity could provide some form of control of the frame rate in 2...

    So far, I had no luck:

    • ...tried setting Application.targetFrameRate to 30 and disabled Sync to VBL, but no change in fps. Still hammering away at 55-60.
    • ...looked for a similar setting to the kFPS #define in AppController.mm for iOS devices, but no luck. Overriding the UnityPlayer Activity in Android doesn't give any similar handle..
    • ...inserting varying Thread.sleep(x) calls in LateUpdate(), trying to maintain ~30ms frametime. This slowed down the framerate of course, but seriously messed with the touch inputs and game experience.

    Does somebody out there have an idea about what I can do to control the fps/main loop for Android devices??


    I can't believe that I'm the only making a "non-action" game for Android that could settle for a lower framerate in exchange for improved battery life..

    Thanks in advance!
     
  2. RefinedGames

    RefinedGames

    Joined:
    Jul 14, 2011
    Posts:
    28
    in my Awake()

    Application.targetFrameRate = 30;

    works fine for me and is both respected in Editor and on device
     
  3. Wrywulf

    Wrywulf

    Joined:
    Oct 12, 2011
    Posts:
    3
    Thanks for your input - it's nice to know that it actually works!

    Hmm... after some testing I just found that v3.3.0 apparently does not honor this setting - neither on Android devices or in the Editor. However, the 3.4.1f5 does!

    So, by disabling Vsync in Quality settings I could control fps via targetFrameRate - perfect!
     
  4. jorge-castro

    jorge-castro

    Joined:
    Jul 26, 2008
    Posts:
    142
    does this have some impact in the battery life or not?.
     
  5. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,369
  6. BlackPanda

    BlackPanda

    Joined:
    Jan 24, 2014
    Posts:
    78
    Did the battery life improve after this??
     
  7. schchang1

    schchang1

    Joined:
    Sep 12, 2012
    Posts:
    8
    Has anyone tested the battery life improvement using new Unity UI system?