Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Stuttering issue on Unity 4.2

Discussion in 'iOS and tvOS' started by rextr09, Oct 3, 2013.

Thread Status:
Not open for further replies.
  1. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    Hi,
    I have recently upgraded my project (Traffic Racer) from Unity 3.5 to Unity 4.2 and published an update to the App Store. Then, I started to receive lots of complains about the performance. I noticed that there was really a stuttering issue which I didn't noticed at first :(
    So, I started to optimize the game until I reach 60 fps on iPod touch 4th. However, the stuttering was still there :(
    I didn't notice it was stemming from Unity itself until I created a very simple scene with 3 draw calls, 30 tris and a simple script that makes the camera flying. Even with this simple scene there were obvious stutters both in my Mac Mini and iPod Touch 4th, although it runs at 60 fps.

    Then, I created the exact same scene in Unity 3.5, and voila!! It was smooth as silk! So I concluded that there is an obvious issue in Unity 4.2 (I don't know if I can generalize it as Unity 4+) Is there anyone who noticed this as well? Or anyone can make an argument that this is not actually a bug and there is a solution to it? Thanks.


    Here is my CameraMover script:

    Code (csharp):
    1. function Awake() {
    2.     Application.targetFrameRate = 60;
    3. }
    4.  
    5. function Update() {
    6.     transform.position.z += 2 * Time.smoothDeltaTime;
    7. }
    (I have also tried vsync on/off, LateUpdate, FixedUpdate, average of smoothDeltaTime and deltaTime, Mathf.Lerp, etc. No luck!)
     
    Last edited: Oct 4, 2013
  2. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    734
    I have had exactly the same issue before (in my racing game) and right after a previous major unity update.

    My first thought would be to try moving your camera update into LateUpdate() it might be a script timing issue.
    maybe previously your script execution order was A then B. now it might be B then A.

    Try running the profiler, it might give you some clues if there are any real performance lags.
    Which could be.... Objects or meshes being instantiated, or sounds being de-compressed.
    Garbage Collect can also cause spikes, but your test scene looks pretty empty with not a lot of object/sound creation.

    btw, can iOS devices run at 60fps ? I think fastest may be 30, try setting target fps to 30, or vSync to every 2 frames.
     
  3. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    JonnyHilly, thanks for the reply. However I have already tried LateUpdate bot nothing changes. In fact, there is only one script running in the above scene, which is the CameraMover.

    And, yes, iOS devices can run at 60 fps, even my iPod Touch 4th can..
    As for setting to 30 fps, I have tried it but again there is a problem in Unity 4+ because it feels like 15 fps when I set to 30fps.
     
  4. howlomogo

    howlomogo

    Joined:
    Jun 20, 2013
    Posts:
    4
    I'm also noticing stuttering issues on iPod Touch 4G with very basic scenes. Still can't get rid of them after optimizing for the last few days. Would be if great if there is a solution to this.
     
  5. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,288
    @rextr09, @howlomogo - it's probably worth using the built in profiler (or the graphical profiler if you have Pro) and share the results with us. I don't know if the stuttering you see happens all the time, or just at certain points, and what devices this happens on. 4.x is generally faster than 3.x, but there's clearly something tripping up your game, so the community will try and help work out what that was. What 4.x features did you upgrade for?
     
  6. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    @Graham Dunnett , ok I will provide the graphical profiler tonight, but as far as I see there was nothing interesting.
    The stuttering occurs on my iPod Touch 4G and Mac Mini (Core i5, HD3000). I'm pretty sure that they can handle the simple scene above with 200+ fps. Therefore, I think the problem may not be a performance issue, but a bug. It just regularly stutters for no reason. (It's like every 1-2-3 seconds).
    I have upgraded to 4.x so that I will be ready to publish for W8 Phone.

    Just to be clear, the simple scene I have mentioned above (3 draw calls, 30 tris, 1 script, 1 directional light) runs smoothly on Unity 3.5.7.
     
  7. howlomogo

    howlomogo

    Joined:
    Jun 20, 2013
    Posts:
    4
    Hi Graham, Maybe I should have started a new thread as I did not upgrade from 3.x but started with 4.2. However I'm also having problems with stuttering on iPod 4. In the profiler Device.Present seems to be between 8ms and 40ms every frame which seems too much I still can't figure out why this is.

    Example with 9000 verts
    $profiler.jpg .

    Example with 40 Verts
    $profiler2.jpg

    I'm not sure if this is what is causing the stutter?

    Thanks
     
  8. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    Here is the profiler shots from the simple scene I have mentioned in the first post. (Using iPod Touch 4g)
    As you can see, both Unity 3.5.7 and Unity 4.2 runs the scene at similar fps. The interesting part is, Unity 4.2.1 has some Overhead (red) sometimes. And Unity 3.5.7 has WaitForTargetFPS (yellow).

    P.S: Vsync was turned off in both of them.

    Unity 4.2.1




    Unity 3.5.7:

     
    Last edited: Oct 4, 2013
  9. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    I've sent a bug report for this. (Case 567610). I hope it's not late for the next minor release, becuse I really need this urgent :(
     
  10. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,010
    Hmm, it's been so long since i used 3.5. Do you have a video of this stuttering?
     
  11. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    @derkoi, I don't have a video but it's easily reproducible using the code above.

    I want to add one more interesting thing which may be related to this issue: My game can run at 60 fps with some stuttering, as I said before. But, if I set targetFPS to 30, the game runs very choppy and looks like it's at 15 FPS, although the FPS counter says it's steady 30 FPS. This can be seen easily on the current version of Traffic Racer on the App Store. (If somebody wants to check it, I can send a promo code)
    In Unity 3.5.7, however, 30 FPS feels really like 30 FPS. (On iPod 4/iPhone 4)
     
  12. markofjohnson

    markofjohnson

    Joined:
    Oct 12, 2010
    Posts:
    68
    See also my thread iOS7 FPS slow down in Device.Present, unity 4.2.1 http://forum.unity3d.com/threads/204247-iOS7-FPS-slow-down-in-Device-Present-unity-4-2-1

    Is this iOS7 only?
    Make a profile build in Xcode and run instruments (Profile option in Xcode). Add the OpenGL profiler, and configure it to show Renderer utilization and tiler utilization. In our case we see Tiler Utilization go from 0 to 5 when Device.Present jump up to 8ms.
     
  13. vladrad

    vladrad

    Joined:
    Jan 26, 2013
    Posts:
    20
    Run your game and use the profiler in xcode. Notice that no matter what you have in the scene the cpu slowly grows and hits 100% on thread one. Then the fps just drops. Anyone else seeing this?
     
  14. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    My problem is not "FPS drops" and not limited to iOS7.
    1) If targetFPS is set to 60, FPS is consistent at 60 fps but there is stuttering.
    2) If targetFPS is set to 30, FPS is consistent at 30 fps but feels very low like 15 fps. (The choppiness increases with the complexity of the scene, while FPS is still at 30)

    I think the first problem is related to vsync but I can't tell anything with the second one.

    Can somebody tell why there is so much difference in the profiler screens above between Unity 3.5.7 and Unity 4.2.1 in the same scene?
     
  15. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    Just tried 4.2.2 and the issue is still there :(. *sigh*
     
  16. markofjohnson

    markofjohnson

    Joined:
    Oct 12, 2010
    Posts:
    68
    Do you have UIKit overlay views? Or has the process used UIViews before opening the unity GL view? Does it make a difference if you set unity back to GLES 1 (instead of GLES 2?)
     
  17. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    I don't know much about UIKit and UIViews. Can you explain them a bit more?
     
  18. markofjohnson

    markofjohnson

    Joined:
    Oct 12, 2010
    Posts:
    68
    By 'UIKit UIViews' I mean native Apple iOS GUI stuff. In fact, even if you never use them yourself, any third party plugins you use for ads etc will put UIViews overlaying your GLView, as is a Game Center login or even the iOS native Control Center.
     
  19. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    No, the test scene I have mentioned has no plug-ins, UI, etc. It has just a script that moves the camera at constant speed.. I can't think of any other scene that is simpler than this.
     
  20. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
  21. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,010
    Thanks, yeah i see what you mean to be honest, i think all my games are like it too :(
     
  22. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    Unfortunately, it becomes very annoying when the car (camera) moves faster in racing games :(
    Most developers do not notice it because their camera does not move fast enough in their games. I hope we can achieve the smoothness of 3.5 soon.
     
  23. jogo13

    jogo13

    Joined:
    Sep 26, 2012
    Posts:
    19
    I have this theory it might be related to float precision... if Unity has changed the float precision on iOS builds to try and optimize a bit that would explain why my scripts that shift UVs get more and more choppier as the games runs while everything else stays constants (frame rate, skinned animations.) The stuttering doesn't show up on my editor.
     
  24. danien

    danien

    Joined:
    Jun 16, 2009
    Posts:
    73
    I don't know if it is related but I had stuttering issues running our game on iPhone 5S with iOS 7 but not with iPad 2 with iOS 6.

    It appears that our problem was we were setting Application.targetFrameRate to 60, but once the game falls below this even for a moment, the entire game begins to stutter frequently. Setting targetFrameRate to 30 removed all the stuttering. On the iPad, it was never running at 60 (around 40+ fps) so we never noticed it.

    Hope this helps someone.
     
  25. gotys

    gotys

    Joined:
    Oct 20, 2012
    Posts:
    16
    @Graham Dunnett - I too have this annoying problem even on Unity Pro 4.3.4 - on my Android HTC One device. My scene is just one ball and one camera and it produces same stutter effect that everyone else is describing here. Can you please let us know if the Unity team is aware of this and is working on resovling it ? I am trying to make a side-scrolling 2D game and the stuttering seriously ruins the experience. Please help
     
  26. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,679
    Wow I'm dealing with this same issue in 4.2. Just some weird stuttering in the simplest of scenes.
     
  27. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    734
    does it only happen with objects that use physics ? if so, maybe its a case of that happening with fixed update being out of sync with the other script or camera updates. Then the order of the updates can change, even if the frame rate does not !!!
    The way to control this is to make sure all of the scripts update in a fixed order...
    e.g. 1) object or physics update, 2) car/object code 3) camera update , then if possible 4) render

    maybe move your camera update call, to be called from the end of the car/object update code, so its always after. try moving code around until fixed update order is guaranteed. try OnPostRender or OnPreRender so code is locked to rendering etc....
     
  28. Duo2k

    Duo2k

    Joined:
    Feb 21, 2014
    Posts:
    1
    I am seeing exactly the same issue as shown on rextr09's video from this thread. My target is Nexus 4.
    The scene is just a ball with a rigidbody using interpolation rolling around a plane and a smoothed camera following it. Smoothed to make sure there wasn't some interpolation missing.

    I also tried removing the ball and physics and moving the camera around and it still stuttered. However when I turned of dynamic batching and static batching the stuttering stopped. When I added some random textured boxes to the scene it continued to run smooth. Unfortunately when I put the ball and physics back, the stuttering returned (although im not sure if it was the same caused).

    My game is 3d top down tile based. With my findings I set the bounding on all my game objects to a large size so they would not get fustrum culled. I then implemented a crude form of quad tree by toggling game objects rendering enabled. With batching turned off this seemed to be an improvement of the situation, although there was still stuttering and there were now drawcalls for every single tile being displayed. Instead of every 2 seconds it would have a more minor stutter every 30 seconds. The improvement was noticeable but not a solution. I would like to be able to remove the stuttering completely.
     
  29. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
    First of all, I think this is not a performance problem but an internal bug, because we are talking about 3 draw calls and 30 triangles with no physics in my first post.
    I think it's more like a buffering problem. Maybe they changed the way buffering works in Unity 4.x. (http://en.wikipedia.org/wiki/Multiple_buffering)

    Since Unity 4.x , the games are more "prone" to stutter even with same FPS. I feel that even a tiny background process cannot be compensated by the renderer and cause stuttering. Therefore it makes me think it's a buffering issue. I hope someone from Unity can inform us about the internal changes they made, which are not present in change logs.
     
  30. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    734
    yeah, maybe they have some kind of update Vs Rendering/buffering bug, where they are independent of each other and "not synced"....
    e.g. fixed frame rate update of objects occurring at say 60 FPS
    Rendering which is opportunistic, and renders as fast as it can, perhaps buffered or not, with desired target of 60 fps. (but not locked to the 60 FPS update rate of scripts or physics) then all it would take is a slight time discrepancy in one or the other, not being exactly 1/60th of a frame each time, and they would occasionally get out of sync... you'd get a burp where maybe the update of objects or physics would happen twice but with only 1 render.

    For example you could maybe simulate this by having FixedUpdate/camera code at 59 FPS and rendering at 60FPS would have similar effect (~1 burp per second)

    anyone try moving all of their update code outside of individual script Update() and just have 1 master control script, that updates in OnPostRender() or OnPreRender() then everything in there is ordered....
    e.g. nothing at all in Update() or LateUpdate()
    OnPreRender masterUpdate()
    {
    moveObject(); //if its not a rigid body
    updateMyCamera();
    }

    does that work ?
     
  31. gotys

    gotys

    Joined:
    Oct 20, 2012
    Posts:
    16
    No, unfortunately my scene has no physics at all, not even camera moves - just my ball object moves across the screen.

     
  32. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    734
    Hrmm
    Does the ball movement use fixed update?

    So it's just a simple gameObject with an update() script that moves it a fixed distance per frame based on time passed, and that glitches?
     
  33. X7Solu

    X7Solu

    Joined:
    Feb 28, 2014
    Posts:
    8
    The problem persists not just on IOS. Same here for android.. created a new empty project in Unity 4.3.4 added a quad mesh with a simple 128x128 Texture and move the thing with translate and Time.deltatime in a Script's Update Function.

    At 60 FPS on my android it looks pretty smooth, but some "hiccups" appear from time to time.

    At 30 - 56 FPS, the whole thing gets EXTREME stuttery, you cannot even watch the quad move from the left to the right of the screen without hurting your eyes..

    Why is that, we are talking about +30 Frames, everything should be smooth.. but extreme laggs/stutters at FPS < 60, while just doing a normal transfortm of a 2D mesh with a texture ?..
     
  34. SteL

    SteL

    Joined:
    Mar 5, 2014
    Posts:
    2
    I was so pleased to see this post as it is the exact issue I am having. All other posts point to the obvious things like not using Time.deltaTime, using FixedUpdate, interpolation not set etc. The video is my exact stutter (I'd know it anywhere by now!) that is driving me crazy. I agree, it can't be a performance issue - I have a Mac with a good spec where I see this issue and an asthmatic Dell machine that does not have the issue. I have gone to the length of installing Unity everywhere to test this! On the Mac I get it on the actual builds and in the editor. I thought it could be just a Mavericks / Unity issue so pushed "the simplest game in the world" to an iPhone but I get the same stutter randomly - say every 1 - 5 seconds.

    Has anyone got any further with the issue?
     
  35. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    734
    Hi SteL, your answer gave me a couple more thoughts...
    You say it stutters on a newer faster machine, but not on old crappy machine... the same code running same unity...
    One difference might be PC unity Vs Mac/iOS unity ? Or pc vs mac hardware ?

    The other might be how the monitor is driven, and the monitor refresh rates.
    For example, perhaps unity is rendering at 30 to 60 fps, and the monitor refresh rate could be anything from 50 to 120hz depending on your monitor, video card and resolution settings...
    Sooooo if Unity is not synced to the monitor update... (or probably even if it does vSync) then this is possibly another way stutter could occur, even is unity is rendering at a smooth fps.

    Could easily test this by changing monitor refresh rate, and seeing if the stutter gets better, worse or goes away.

    If not synced with monitor refresh rate, then maybe only when the game is at same rate as monitor, (or exact multiple), then there won't be a stutter.
    i.e. (game monitor=60) (game=30 monitor=60) (game=60 monitor=120) (game=40 monitor = 120)

    ...OR if game can render faster than monitor refresh rate, and is synced with monitor, then there won't be any stutter.

    maybe unity broke the vSync ?

     
    Last edited: Mar 5, 2014
  36. X7Solu

    X7Solu

    Joined:
    Feb 28, 2014
    Posts:
    8
    Has probably nothing to do with the monitors refresh rate, because if you push a simple game on an iphone or android device , it will lag, no matter what..
     
  37. SteL

    SteL

    Joined:
    Mar 5, 2014
    Posts:
    2
    I have just discovered something interesting. On the PC where the simple moving camera game works perfectly, I have a dual monitor setup. I have just noticed that it only works perfectly on one of the monitors. I can swap the game while it is running, between the screens and see the obvious difference. The secondary LCD monitor gives the exact same stutter as on my Mac where the primary display runs perfectly. I have tried the monitors individually and confirmed this is still the case. Even if I swap primary / secondary it is the same monitor that shows the stutter. The monitors (one Lenovo, one Dell) both report they are running at 60Hz and are both the same resolution. This is with vSync on - with it off the issue is less noticeable.

    To compound the madness, if I put it between the two monitors - half on one and half on the other, the monitor that usually stutters shows it perfectly, the usually good monitor shows the stuttering!

    What to make of this I don't know!
     
    Last edited: Mar 6, 2014
  38. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,679
    So anyone have any info as to what might be causing this? I'm experiencing this stuttering on some very simple scrolling scenes on Android. As a side note I run a dual monitor setup and all Unity editor playing runs slower on the secondary monitor.

    EDIT - Just tested something. I switched the build settings to OpenGL ES1 vs OpenGL ES2 and my movement was smooth as butter without a hiccup. However weird artifacts started happening and parts of my world stopped rendering.
     
    Last edited: Mar 10, 2014
  39. X7Solu

    X7Solu

    Joined:
    Feb 28, 2014
    Posts:
    8
    how that ? , I can just choose ES2 in the settings for android..
     
  40. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,679
    Ah you may be on a version of Unity later than 4.2 or something. They may have removed that feature, not sure. I do know I actually traced the culprit in my scene back to some real time shadows.
     
  41. JonnyHilly

    JonnyHilly

    Joined:
    Sep 4, 2009
    Posts:
    734
    I would guess that unity can only vsync with one of the monitors (primary ?) and not both. and that both monitors perhaps are slightly out of sync, would guess that dual monitor setups don't sync with each other.

    some interesting info here on tearing, sync and multiple monitors..
    http://www.derivative.ca/wiki088/index.php?title=Vertical_Sync_and_Horizontal_Tearing
     
    Last edited: Mar 14, 2014
  42. Shaka

    Shaka

    Joined:
    Apr 24, 2010
    Posts:
    51
    Hello!

    I'm developing an endless game with 2d toolkit (IOS Android) and I have the same problem with my scrolling scenery. It's pretty bad when trying it out on my Samsung Galaxy S2, but on my wife's iphone 4s it's nearly unplayable. I tried changing my camera translation code to use smoothDeltaTime and it got better on the S2 but it's still really bad on the 4s. I've tried making a bare bones scene with with the same result, and the profiler doesn't seem to detect any spikes. I have no idea what else to do....maybe crying will work?
     
  43. gotys

    gotys

    Joined:
    Oct 20, 2012
    Posts:
    16
    Correct .. And I tried all kinds of voodoo with fixedUpdates vs. normalUpdates vs. deltaTimes...etc. This is not a problem of coding - like everyone here tries to suggest. There is virtually nothing one can write in their code to fix this. Only way we can get this resolved is to make sure the Unity team is aware of this and cry loud enough so that they fix it.
     
  44. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,851
    Please submit a bug report!
    Thanks
     
  45. gotys

    gotys

    Joined:
    Oct 20, 2012
    Posts:
    16
    Please, if anyone submitted this issue to Unity team , I'd like to vote on it ( if possible ) , give me a link so that I can vote UP.
     
  46. caseyc

    caseyc

    Joined:
    Jul 2, 2012
    Posts:
    15
    Having this issue with our game as well. If anyone has a link to a bug report I will gladly vote, or if it has been discovered what the issue is please let me know!
     
  47. gotys

    gotys

    Joined:
    Oct 20, 2012
    Posts:
    16
  48. rextr09

    rextr09

    Joined:
    Dec 22, 2011
    Posts:
    416
  49. gotys

    gotys

    Joined:
    Oct 20, 2012
    Posts:
    16
    Yup, we are on a good way :)
     
  50. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Excellent, but now lets just hope it is released quickly in the next build as well as the issue with slow iPhone 4 start-ups.
    Really need a new build soon to help with this mobile stuff.
     
Thread Status:
Not open for further replies.