Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

2D Android apps stutter and can't maintain a smooth 60 fps

Discussion in 'Editor & General Support' started by Spuddicus, Apr 3, 2015.

  1. Spuddicus

    Spuddicus

    Joined:
    Aug 11, 2014
    Posts:
    15
    I just can't get a simple 2D Android game to run smoothly at 60 fps. They always stutter every few seconds and look like an amateur has coded them. I have no problems with iOS - the same games run silky smooth at 60 fps on all iPhones and iPads I've tested on without a single glitch. After searching the internet for possible solutions, I came across several people with the same problem over the years but still no solution. Some people blamed garbage collection, others the fixed physics update being out of sync with the main update loop but still no solution. So I decided to write an extremely simple test project to demonstrate this stuttering problem on Android. It would be great if people with Android devices could try out the two apk's I've attached and see how smooth they run on their devices. All this project does is move three 2D sprites across the screen at 2, 3 and 4 pixel increments. I calculate the value I need to add to their world's x position to get exactly 1 pixel of increment and then multiply that value by Time.timeDelta * 60.0f in their Update loops. If the device is running at 60 fps, as it should be with such a simple demo, then I would expect Time.timeDelta to be 0.01666666 every Update so Time.timeDelta * 60.0f should come out to 1. This should result in the silky smooth motion that 2D games demand, and it does on iOS ... but not on Android. Every few seconds there is a stutter. Sometimes it's better or worse than others but never flawless like iOS. There is no rigid body physics to blame and nothing going on that might cause CPU spikes or garbage collection. It's as simple a demo as it gets. I really hope Unity can fix this problem as every 2D game I try to write for Android ends up with little stutters in it and doesn't look very professional at all.

    I've attached the project files and two pre-built Android apks - one is built with Unity 4.6.3 and the other is built with Unity 5. The Unity 5 version actually stutters worse than the one built with 4.6.3 on my HTC One V but the other way round on my Nexus 4. Please look closely as sometimes the movement looks really smooth but then hiccups slightly every couple of seconds. It's easiest to see if you watch the fastest moving sprite. If people could post their results here, for both versions and what device they were testing on then maybe Unity will take this problem seriously. Thanks!

    Doesn't look like I can upload the apks here so here are download links to them:

    http://www.digitalsmoke.us/TestUnity4.apk
    http://www.digitalsmoke.us/TestUnity5.apk
     

    Attached Files:

  2. YuriyVotintsev

    YuriyVotintsev

    Joined:
    Jun 11, 2013
    Posts:
    43
    Same problem with my games. Tested everything I find, but nothing helped.
     
  3. Spuddicus

    Spuddicus

    Joined:
    Aug 11, 2014
    Posts:
    15
    Running the two tests on my Nexus 4 phone - the Unity 5 build does actually run at a silky smooth 60fps with the Unity 4 build stuttering away as usual. So it does appear that something has happened with Unity 5 to fix this problem. However, I've run both tests on my older HTC One V phone and the Unity 5 build is actually a lot worse than than the Unity 4 build. I'm not really in a position to build using Unity 5 though as our game uses a lot of third party stuff that doesn't work in Unity 5 yet. Facebook SDK springs to mind so I hope Unity can apply whatever they've done in Unity 5 to a Unity 4 build.
     
  4. Zeblote

    Zeblote

    Joined:
    Feb 8, 2013
    Posts:
    1,102
    No problems with either apk on my nexus 5, you didn't include an fps counter but it *looks* like they are running at a smooth 60 fps with no hickups. :)
     
  5. Hiti3

    Hiti3

    Joined:
    Jul 16, 2015
    Posts:
    7
    Hey there, I have the same same same problems. Can we really not maake good games with Unity2D? :( Should we really code our own physics? Is this really the problem with FiexUpdate()?
     
  6. Spuddicus

    Spuddicus

    Joined:
    Aug 11, 2014
    Posts:
    15
    I guess that's why it's called "Unity 3D" ;)
     
  7. outasync

    outasync

    Joined:
    Mar 1, 2014
    Posts:
    48
    Hi,

    I have had the same problem, and I have managed to fix my game using the following techniques,
    • Make sure everything is a prefab (except any object that doesn't have a renderer), this step is especially important for sprites with alpha and do this even if you only have 1 in your scene
    • If using Physics 2D, make sure any changes to rigidbodies are done in FixedUpdate, this is quite standard but is often overlooked.
    • If using Physics 2D + rigidbodies, make sure only your main character has Continuous collision, everything else should be discrete.
    • Graphics settings V Sync - Every V Blank
    • If you are making a simple 2D game, deleted all the quality profiles except simple and turn v sync on for this profile
    • Before you build your apk go to the Android player settings, Other Settings, untick 'Auto Graphics API' and only add OpenGLES2 do not use 3 or even add it, its performance is terrible. You can also turn on multithreaded rendering if you still can't reach 60fps
    These worked for me, I went from Unity 4.6 getting 60fps to Unity 5 and getting under 45fps on the same project, after a week of various tweaks my game now runs smooth; never drops below 60.

    Sync
     
    Stevie33, Rajmahal, MrEsquire and 2 others like this.
  8. outasync

    outasync

    Joined:
    Mar 1, 2014
    Posts:
    48
    Random lags during gameplay are often audio related,
    • Sound effects should be short WAV files, decompress on load, ADPCM, preload audio data
    • Music should be ogg ,mp3 have problems with music loops in Unity, set as stream, vorbis and preload audio data.
     
    Rajmahal and MrEsquire like this.
  9. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Good post, would be cool to see if Unity 5.3 has helped things.
     
    JamesArndt likes this.
  10. TobyYe

    TobyYe

    Joined:
    May 25, 2013
    Posts:
    24
    I am developing a simple 2d game. It's strange that it got stable 60 fps on ios device (iphone 6,6s,7p), but not on android device. I got stable 40+ fps on my old samsung galaxy s5 mini, but got untable 60fps(some times suddently drop to 40, which cause a lag) on Sony Xperia™ Z3 Tablet Compact. I search the internet and try evey method to optimize the game but fail. So I create an empty project to test.

    The result is :
    Empty project android build frame rate not stable(some times jump from 60 to 40 in very short time). I test the project in 2 device, one is samsung galaxy s5 mini. it work well and keep the fps at 60 very stable. The other one is Sony Xperia™ Z3 Tablet Compact, it support to be stronger than s5miin, but sometimes the fps will drop suddently to around 40, it will cause some lag on my game that under development. The both devices are android 6.01. And some of my friends test my game with recently release andoid phone also feel lag on my game.

    The attachment is my test project. Pls some help me to solve the problem.
    https://www.dropbox.com/s/ht6jhszlf6txa84/FpsTest.zip?dl=0
     
unityunity