Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Stuttering with vSync

Discussion in 'Editor & General Support' started by fox, May 30, 2012.

  1. fox

    fox

    Joined:
    Jan 14, 2009
    Posts:
    110
    Hi,

    We're experiencing performance issues related to v-sync, causing stuttering behavior in our game. The game is using a triple monitor setup, managed through the Nvidia Surround system. The total resolution is 5760x1080.

    The issue is best understood via the images below, which shows sections from the profiler for both the v-sync settings (every Vblank/every second Vblank). Using the setting every second Vblank causes serious stuttering, as seen on the image. The stuttering seems to origin in the actual Vsync (Graphics.PresentAndSync), which causes lag spikes that are immediately followed by matching drops. It's like Unity is doing something twice on one frame, and skips it on the next.

    The behavior was reproduced in a completely empty project as well.

    Any ideas?

    every second Vblank


    every Vblank
     
  2. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    ok so far as we know vsync normally locks the screen refresh rate to match your computer screen in order to fix tearing and so forth. if you don't use the vsync you will notice a increase on the framerate a lot. if you just open a empty scene with just the camera you will see the difference, leaving at every blank would lock the frames closer to 60 fps range which is mainly the ideal range for standalones and every second blank would go more lower down to 30 fps so that's why it will lagg as we so call and use as a main word. so the profiler it's correct, that it's not a error this is how the vsync in unity works. one question would be why they have every second vblank? and it goes down up to 30 fps, well this is mainly to target the iphone and the android so if you have lots of things one the scene you might want to start optimizing maybe? and yes i might be wrong in some areas, this is just the main understanding i have when woking with vsync in unity.

    for example other things i notice too is when you are using fixedupdate vs regular update the vsync actually has some impact on the fixed one in some way of what i got from my findings, good luck
     
  3. fox

    fox

    Joined:
    Jan 14, 2009
    Posts:
    110
    Yes, the purpose of the vsync is to lock the refresh rate to match either the screen refresh rate or half the screen refresh rate. However, our problem is not related to the FPS, but to the dysfunctional behavior of the every second VBlank setting. The expected behavior would be a constant 30FPS, as with the constant 60FPS obtained using every VBlank.
     
  4. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    perhaps your resolution? i'm running a dual screen and i do seem to have problems with my builds when i have both screen on until i turn one of them off, besides the fact that your resolution it's big. maybe it's overpowering the vSync from unity? have you just tried it withouth the vsync? do you have to have the vsync?

    lol we are both foxes.
     
  5. fox

    fox

    Joined:
    Jan 14, 2009
    Posts:
    110
    We're using the vsync to have a smoother game play, which works out well except for the strange behavior discussed here. vSyncing to 60FPS would of course be preferable, but that's really not an option with the project we're working on due to it's extent and high quality expectations. We have to settle for 30 FPS (which in fact looks very good in between the random stuttering we face).

    Yes, it might possibly be related to the resolution, but as it's not an option lowering it we're unfortunately pretty much bound to solve this problem. Anyone at UT having any input on this one?
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,600
    Check your driver settings.
    If you are controlling the hardware in your case, you might actually want to favor the driver profile possibilities as the are on the 'mess with it layer', while Unity can only try to request it but its in the end up to the driver to handle it.

    Did you try and see what happens if you use vsync every blank + Application.targetFrameRate = 30?
     
  7. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    26
    Hey,

    I have noticed the exact same thing although I don't have Unity pro so no profiler but I notice a frame rate stutter what feels like every second or two.

    Every second there seems to be a regular jitter in the rendering/timing of the application that is so noticeable that it is a total deal breaker for both my project and my potential upgrade to Unity Pro.

    I find it is even noticeable in Angry Bots although you have to look pretty close to see it because there is so much going on like the rain etc.

    In searching for a solution I have seen quite a lot of people with similar sounding issues but no real answer.

    Tonight I am going to revert to Unity 3.4.2, create a 3.4.2 version of my test scene and see if it happens there because I certainly don't remember this being an issue. If it is something that happened with the update to 3.5 then hopefully it will get some attention and a fix.

    I will post back with the results of my 3.4.2 test later.

    Regards

    EvilNoodle
     
  8. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    26
    Just reverted back to 3.4.2 and there still seems to be a stutter.

    The test scene I am using is as follows:

    1) Create a default new scene

    2) Set the default camera's background to black

    3) Add a particle emitter with the following properties...
    ==> Position : 0, 10, 0
    ==> Ellipsoid : 10, 0, 1
    ==> Local velocity 0, -5. 0

    4) Set the quality level to "Fantastic".

    5) Add the following script to the camera to enable an escape quit for stand alone build...

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class EscapeQuit : MonoBehaviour
    6. {
    7.  
    8.     void Start ()
    9.     {
    10.    
    11.     }
    12.    
    13.     void Update ()
    14.     {
    15.         if(Input.GetKeyUp(KeyCode.Escape))
    16.         {
    17.             Application.Quit();
    18.         }
    19.     }
    20. }
    21.  
    On my system there is a noticeable stutter every second or so both in the editor and a standalone build (less severe in the stand alone build but still noticeable).

    My system specs are an i7 running at 3.2Ghz, 6 Gb ram, Nvidia 580, Windows 7 Ultimate 64 and it should not have any problem running this. I have also replicated the issue on my GF's system which is the same except for an i5 processor and Nvidia GTX295.

    Short of a total system rebuild I have totally run out of ideas on how to investigate and/or fix this now!

    EvilNoodle
     
  9. fox

    fox

    Joined:
    Jan 14, 2009
    Posts:
    110
    can you please elaborate this part a bit? we actually do control the hardware, so anything available via the nvidia control panel is an option to consider. however, we've already tested using the vsync from the control panel instead of from Unity, with the same result (I suppose it's actually the same thing though?). also tested the all new Adaptive options.

    combining these two isn't possible, according to the docs: If vsync is set in quality setting, the target framerate is ignored, and the vblank interval is used instead.

    instead I tested combining the nvidia vsync and a target frame rate, unfortunately without any better results.

    this might be related, however the stutter we're experiencing isn't on a specific interval, but instead completely irregular. worth noting is that we're both using nvidia cards on Win7-64 systems.

    we're doing some more research during the day, and we'll post any possible findings. appreciate all your ideas so far!
     
  10. foxter888

    foxter888

    Joined:
    May 3, 2010
    Posts:
    530
    since you said that your project is a high quality vsync doesn't really has to deal much about helping out the frame rate, sometimes those spikes are things such as the drawcalls and so on. so my question would be are 1) what platform are you targettting? 2) what is your drawcall counts? 3)do you have somebatches too? it seems that maybe you might need to optimize your scene more.
     
  11. fox

    fox

    Joined:
    Jan 14, 2009
    Posts:
    110
    this topic isn't about optimizing, as stated in the original post we also tested in a completely empty project.

    our recent findings are that this problem might be caused by faulty drivers on our cards, the v-sync seems to be corrupted on some nvidia cards (read more in this article. the cards mentioned in the article is in the 600-series, but we have two 560Ti cards. However, searching around gives us hints that the problem might also be existing in the 500-series. according to the article, a driver fixing this problem is upcoming (hopefully in June).

    we also tested running Need For Speed using vsync, and got the exact same stuttering behavior found in Unity. so unfortunately it seems to be just a matter of waiting, and hope that the new drivers solves this issue.
     
  12. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Maybe try one of the beta nVidia drivers?
     
  13. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,189
    This is a very interesting thread, as I am currently having a very hard time determining why my scene(s) seem to be lagging/jittering when I'm moving around my gameworld. It's hurting my eyes quite frankly.

    I have an rts style game, and I move my one camera (scrolling it like in most rts games) with a script that moves my camera backwards, forwards, left and right when a user moves their mouse to the edge of the screen.

    During the camera scrolling it seems like unity is having a tough time keeping up with the framerate or something. It's as though every so often the screen lags behind where it's supposed to be. Using the stats option "in-game" I have some spots on my scene where I am getting 800+ frames per second, a 1.2 ms main thread (not sure if that's quick or not), Renderer at 0.2 ms, with 9 draw calls, and I still get this jittery frame lag when scrolling about my scene.

    Obviously turning v-sync count off in my project settings > Quality settings helps a lot, however it does not eliminate the problem. It really does seem vsync related. I've tried deleting most of my game objects in my scene, along with disabling almost all of my scripts in the project, and yet it still seems to happen.

    I just tried updating my own graphics drivers (I have an ATI Radeon 4850), and it did not fix the problem. My only idea now is to try setting my screen refresh rate to a different rate in windows and see if that fixes anything.

    Forgot to mention specs, I am using Windows 7 Home Premium 64-bit, AMD Phenom x4 3 ghz processor, 6 GB ram, radeon HD 4850 graphics card.
     
    Last edited: Aug 13, 2012
  14. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    26
  15. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,189
    Thanks for the tip EvilNoodle :) I simply changed my windows refresh rate from 60 hz to 100 hz (fortunately my flatscreen has these options), and it runs much smoother now.

    Something to note though, is that for some reason it runs smooth at 100 hz, but when I try my monitors refresh rate at 120 hz, it seems to have problems again (although better than at 60 hz still). It's really weird. My refresh rate was set correctly in my ATI drivers settings, so that was not a problem at all.

    In short 60 hz - bad. 100 hz smooth (but not perfect). 120 hz - smoother but still noticeable stuttering.

    At least 100 hz works for me for now. Thanks again EvilNoodle.
     
  16. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,189
    Okay, so even though setting my monitors refresh rate to 100 hz helped smooth out this frame "blipping" quite a bit, it did not completely eliminate the problem (even with vsync off and such).

    I've been looking into it further, and came across someone having the same problem. They said that turning the quality settings to "fastest" in project settings, and then building and running the game (selecting the "fastest" option again), seemed to work for them. Although even with "fastest" quality in the editor, the blipping is still noticeable.

    I tried this myself and it worked (i'd say about 99% worked lol). The blipping/jittering almost completely went away when the game was built with "fastest" quality settings -- however I must mention that I could notice some miniscule blipping still, but not game-breaking at all and I had to look really hard for it. Again this is with the game actually built.

    Just wanted to throw this out there in-case anyone else might be able to benefit from it.
     
  17. simcovr

    simcovr

    Joined:
    Jul 3, 2012
    Posts:
    42
    Hi!

    Just to bring my experience with this issue:

    first of all: I think I found the solution :)

    The problem is that if you leave the application to use the vsync, Unity use the windows value (59Hz). This cause stuttering.
    To use vsync, you have to switch off the option in the application and force ON on you graphic driver.
    Unity report 60fps and no stuttering at all.

    Hope this help.

    Regards
     
    WatchYourVector likes this.
  18. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Changing the V-sync settings in the NVidia control panel to force v-sync on did make "Graphics.PresentAndSync" consuming a massive 10ms go away.

    Is this an issue with Unity trying to use the wrong V-sync value?
     
  19. Neeko

    Neeko

    Joined:
    Mar 9, 2012
    Posts:
    24
    *blows dust off the thread*

    So I'm experiencing a similar issue using Unity 4.3.2. If I turn on VSync in the project's Quality settings, I'll frequently get a high framerate spike (over 100FPS), and a strong stutter for a few frames, and then it drops back down to 60FPS and runs normally. However, if I turn off VSync in the Quality settings, and force it on in the Nvidia Control Panel, I don't experience that issue.

    Can anyone explain why when Unity uses the Windows value of 59Hz stuttering is present? Is there anything that can be done to circumvent it? I'd imagine other Unity developers have used the built in Unity VSync with success before (or maybe not?!) so I'm hoping I'm just doing something wrong on my end.
     
    Last edited: Apr 10, 2014
  20. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    131
    Umh, i have this stuttering problem only in giant scenes with over 2M tris, the frame rate go at 60fps, but i have a lot of stuttering, if i not use vsinc the stuttering go away but i have an unstable frame rate (180fps-38fps) and a lot of tearing.
     
  21. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    23,579
    Sounds like lots of garbage. Check the profiler.
     
  22. Neeko

    Neeko

    Joined:
    Mar 9, 2012
    Posts:
    24
    I'm using the free edition so I can't do that, unfortunately (I'll save up for a pro license one day!). Could it really be GC? I am pooling my objects that get instantiated frequently (projectiles, etc) and the type of stuttering I'm seeing isn't a GC pause; the stutter can last for several sequential frames as well as be consistent at lower resolutions. Even when nothing new gets instantiated in the scene, I experience it.

    Plus, if it were GC pauses, why would the stuttering disappear completely with VSync turned off? Also, memory doesn't seem to be bloating in Task Manager.

    By the way, loved The Other Brothers!
     
    Last edited: Apr 12, 2014
  23. instruct9r

    instruct9r

    Joined:
    Aug 1, 2012
    Posts:
    119
    hi guys.
    I was wondering if you were able to fix your issue and if yes, what was causing it?

    I am having similar problem. When i set my game to run on 60FPS it runs like a blueray movie. It's great. But when i set it to 30FPS (Every Second vBlank) these lags begins, every few moments. If i profile, the profiler is allmost a straight line, there are no ups \ downs, the FPS stays between 29.95 and 30.03, but these spikes occurs all the time...

    thanks
     
  24. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    23,579
    Hiya :) if you're on mobile then there's the console dump which shows allocations if you want to check that. If not, then try the game on standalone build - it could be just a Unity editor thing.
     
  25. instruct9r

    instruct9r

    Joined:
    Aug 1, 2012
    Posts:
    119
    I am going to upload development build for you to check with the profiler, if anyone can. I am just wondering... Can somebody extract something from the build of the game, if it's development build? Cuz i'm going to add my main character in the build??
     
  26. reppiz01

    reppiz01

    Joined:
    Oct 20, 2012
    Posts:
    10
    Same Problem here...
    Stuttering with targetFramerate = 60,
    Stuttering with VSync On, every blank, every second blank...

    tried different ways of move the transform (lerp, set position directly, transform.translate, moveto, with deltatime, without deltatime, with smoothdeltatime).

    i have an i5 processor and the integrated graphic unit (intel graphics hd 4000) .

    i run out of ideas - it´s very frustrating...