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. CodeMonke234

    CodeMonke234

    Joined:
    Oct 13, 2010
    Posts:
    181
    Mantas - I am trying to replicate the error in a new project so that I can submit bug report.
    In this project, I can replicate the error in the mac editor - there is definitely an issue (5k retina imac).
    A remote worker is getting stuttering on an iphone6, but I have been unable to replicate it yet on any of my ios devices.
     
  2. DarkNeo

    DarkNeo

    Joined:
    Apr 27, 2014
    Posts:
    53
    I am also having the same issue. I will suss out my Profiler and see what's going on with mine. But here are the best results I have found.

    Windows / Mac builds I leave Vsync On, I turn off the targetFramerate = 60 and my character's code is using FixedUpdate(). These settings work decent for me. The game is smooth 99% of the time then every now and then you get a tiny little blip. Which is annoying because It's not 100% smooth, Any other settings I have changed make the game worse.

    For iOS devices I use the same settings however I make sure targetFramerate = 60 is on in my Awake() I have only tested the game on my iPhone 6 plus and my iPad Air. The game runs decent and best it has ever run, the game looks smooth however it still get's that tiny little lag spike, and sometimes after a couple of deaths the game is quite laggy but then when you die its back to being fine again. It's too random.

    I still need to test this on my brothers Android device I need to download the latest SDK. I suspect it will behave the same though.

    I'm running this all in Unity 5.0.1, I upgraded last night to the latest 5.1.1 and it was even worst with these settings, I downgraded to 5.1.0 and it was still bad so I just went back to 5.0.1 again, I am going to test it out on some of the other versions too.

    This Stutter issue will not defeat me!! :p

     
  3. Mafutta

    Mafutta

    Joined:
    Sep 30, 2014
    Posts:
    29
    I have it on windows with unity 5.1.2.f1 , even for simple sideways camera waypoint game. The stutter ruins it completely.
     
  4. Jakhongir

    Jakhongir

    Joined:
    May 12, 2015
    Posts:
    37
    having this issue in unity 5.1.2f1 also, I see fps drop and cpu rises 100-103% in Xcode when jittering happens
     
  5. Moriot

    Moriot

    Joined:
    Sep 12, 2015
    Posts:
    2
    Damn! the guy who started this thread has 100,000,000 installs on Google play ...on the app that was showing lags damn!
     
  6. tng2903

    tng2903

    Joined:
    Apr 8, 2013
    Posts:
    35
    Is there any update about this issue? It's been a long time, and we are now at Unity 5.3.1 already :D
     
  7. Wiliz

    Wiliz

    Joined:
    Feb 18, 2014
    Posts:
    20
    @Mantas Puida

    We have noticed that calling -[NSRunloop acceptInputForMode:beforeDate:] at the end of UnityRepaint() (which I assume is your fix for input responsiveness,) is causing significant frame drops in some cases. Calling it at the beginning of the frame instead seems to be much better for performance, and I would assume it still has the same effect on input responsiveness as well.

    I have submitted a bug (767405) with a simple reproduction project and some analysis.

    For anyone who is having random performance issues, but thinks their game should run at solid 60 fps, there is a simple test. Just move the following code to the beginning of UnityRepaint() in UnityAppController+Rendering.mm in the Xcode project. (This is in Unity 5.3.2, the exact code might be slightly different in other versions.)

    Code (csharp):
    1. #if ENABLE_RUNLOOP_ACCEPT_INPUT
    2.         static NSDate* _past = [NSDate date];
    3.         if (_enableRunLoopAcceptInput)
    4.         {
    5.             [[NSRunLoop currentRunLoop] acceptInputForMode:NSDefaultRunLoopMode beforeDate:_past];
    6.         }
    7. #endif
     
    Last edited: Feb 3, 2016
    MrEsquire likes this.
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    6,126
    Is there a decent workaround for this? I tried the suggestions on this thread, they didn't really help and development on 4.x has already stopped.

    So the only chance of fixing this is if there is a decent workaround we can implement ourselves.
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    6,126
    (RANT: Ok, so this is an important issue, it has been VERY WELL documented, multiple times (this one is even closed : https://fogbugz.unity3d.com/default.asp?586933_i71f6o2c5c2i58r4 ), is a regression from Unity 3.x, it still hasn't been fixed AND it will never be fixed for Unity 4.x users... it's unrelated, but suddenly I feel less optimistic about Enlighten getting into a workable state in forward/gamma in 5.x)
     
  10. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    You should not be shocked at all, if you read the Unity 5.3 performance thread..you see the main problem with Unity is mobile performance, they are struggling with this..Do not know who is to blame, poor QA testing for not noticing such issue (most likely) or the push to keep adding new features to iOS. We still do not have watch support btw, so I cannot be optimistic at anything!.. Really we should make a new thread for 5 series.
     
  11. tng2903

    tng2903

    Joined:
    Apr 8, 2013
    Posts:
    35
    Great idea, since, I think, the mods stopped coming to this thread a long time ago
     
  12. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    800
    @Mantas Puida @Yury Habets
    Any progress on this? I still see it on ANY platform : editor, ios, android. Didn't test the others but I am pretty sure it's the same.
    And I am sure it's not an issue with my code cause you can notice it even on an empty scene with a particle system firing vertically.
    I don't know how you guys cannot see it, it's very noticeable. I can make a video if you need.
     
  13. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,851
    What's your bugreport number for iOS?
     
  14. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    800
    Preparing it.
     
  15. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    800
    After further testing it seem it was a combination of device barely keeping up ( was testing on iphone 4 and another crappy android device).
    Sometime a single frame take longer than normal on such low end devices, probably due to OS and or something Unity is on the native side and this is noticeable as the things start moving at bigger deltas to be frame independent.

    Does Unity perform anything other than GC( I have zero runtime allocation) that is not fixed per each frame?
    I see in the profiler sometimes certain methods that normally take 2-3 ms goes up to 30ms and even 130ms in rare occasion in these devices.
    If Unity doesn't do anything than must be the OS.
     
  16. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    800
    Finally found the issue, seem that even when doing nothing onAudioFilterRead allocate memory every frame which results in GC very very often which create jerkiness.
    This is common to all platforms not just IOS, and I think it should be preallocated( which from what I read, it was preallocated and shared among all scripts before, so it must be a regression).
    Took me the whole day to isolate it, hopefully it will be fixed.
    Here is the bug :
    https://fogbugz.unity3d.com/default.asp?784150_7ps6gh608dq9o3t8
     
    MrEsquire likes this.
  17. dialtana

    dialtana

    Joined:
    Oct 17, 2015
    Posts:
    3
    Since 2010 the problem occurs and Unity has solved nothing. Start new project, a single image in low resolution and vertical animation and stutter or lag occurs, whether PC, IOS or Android. Thousands of complaints in forums and do not solve anything, is really UNITY an engine for 2d games ???

    I'll try Godot V2.0.2 that is simpler and test if error happens.
     
  18. Mantas-Puida

    Mantas-Puida

    Unity Technologies

    Joined:
    Nov 13, 2008
    Posts:
    1,851
    That's not something we are seeing on iOS on our side. Please submit a bug report with the project that reproduces this on iOS.
    Thanks!
     
    JamesArndt likes this.
  19. polymoongames

    polymoongames

    Joined:
    Aug 17, 2017
    Posts:
    6
    I am having the same issues. I have only 1 camera 1 moving object on x direction and a tiled background to see if the camera stutters . I have tried with both unity 5.2 and 2017.1 but no luck. The results are the same. vsync was affectting me a lot but even turning it off helped a bit but decreasing fixed time made it sooooo smooth. http://www.skgames.net/wp-content/uploads/2013/10/Unity_4_2_2_Stuttering.mov (This is not my project but the problem is same) In my scene there is only 1 main camera 1 moving object on x and a tiled background. I have been trying to figure this out for 5 days but :/ I dont know what to do. I surely believe my codes are not the problem since the code is only 1-2 line but if you wonder here it is : (This is for the basic project only camera following a moving object on x direction with a tiled background (in order to see if the camera stutters or not))


    Public class MovingObjectScript : MonoBehaviour {

    public static MovingObjectScript instance;

    [SerializeField]
    private Rigidbody2D myRigidBody;

    [SerializeField]
    private Animator anim;

    private float forwardSpeed = 2f;

    void Start()
    {
    SetCameraX();
    }

    void FixedUpdate ()
    {
    Vector3 temp = transform.position;
    temp.x += forwardSpeed * Time.deltaTime;
    transform.position = temp;
    }

    void SetCameraX()
    {
    CameraScript.offsetX = (Camera.main.transform.position.x - transform.position.x) - 1f;
    }

    public float GetPositionX()
    {
    return transform.position.x;
    }

    This is for the moving object.

    And this is for the camera

    public class CameraScript : MonoBehaviour
    {
    public static float offsetX;

    void Update ()
    {
    MoveTheCamera();
    }

    void MoveTheCamera()
    {
    Vector3 temp = transform.position;
    temp.x = MovingObjectScript.instance.GetPositionX() + offsetX;
    transform.position = temp;
    }
    }

    Besides this I have tried to get the old position in the update and carrying to the new position in late update it gives a slightly better smoothness. Using fixed time with a value of 0.2 makes it horrible (The stutter is so obvious when its 0.2). Using only update with 0.2 still bad. I am about eat my brain because of this error. I want to solve this permanently without changing fixed steps. If someone can help me solving this problem. I will pray for him/her :) (All this made with without vsync. When I turn it on it goes really bad and even decreasing timesteps dont help it)
     
    Last edited: Aug 20, 2017
  20. polymoongames

    polymoongames

    Joined:
    Aug 17, 2017
    Posts:
    6
    I meant 0.02
     
  21. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,679
    Did you try out different interpolation methods for the Rigidbody? Usually smoothing that out will help. Also your camera movement code is in Update and should most like be in LateUpdate.
     
  22. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    I am seeing the same issue as well; an empty project with nothing except basic continuous movement (be it horizontally scrolling, vertically scrolling or a particle system emitting a couple of particles).

    I notice that the same stutter occurs 90% of the time when doing a single "touch down" on iphone. rapid taps don't seem to initiate a stutter; it's just that initial tap each time. This issue was reported by JohannesDeml and he provided a repro (https://github.com/JohannesDeml/Unity-ios-touch-input-stuttering) although I do not know the case number of his bug report.

    Looking over this thread it is interesting that there is input related logic that influences the vsync stutter given that touch input is causing the same stutter to occur; at least for me and JohannesDemi.
     
  23. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    The rendering in my game is very very basic and the profiler seems to suggest that there is no bottleneck... it looks very spiky though:

    upload_2017-12-7_6-57-10.png

    The tallest spikes are "WaitForTargetFPS" and the stutters seem to occur in the largish slices where there is no "WaitForTargetFPS" spike as shown in the above screenshot to the right of the selected frame.

    Also, the GPU is hardly being pushed:

    upload_2017-12-7_7-0-2.png

    The stutter occurs when running at the screen refresh rate 144fps/144hz 120fps/120hz 60fps/60hz on two entirely different monitors. The problem also occurs on OSX and on mobile.
     
  24. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    I am observing the same stuttering on windows and on iphone (from app store) for other games that I know were developed using Unity such as "Hearthstone" and "Bad Piggies".

    If I stare at a continuous animation, such as the spinning ring (Hearthstone) on the entry part of the game it stutters at the same rate as I am observing in a very simple empty scene with a scrolling texture.

    The stutter on tap is also apparent on mobile. This leads me to believe that the stutter is somewhere within Unity rather than the games themselves since the stutter is not happening in games that were made in other engines such as "Tiny Wings" which has flawless animation.

    The stutter is noticeably worse with continuous scrolling quick reaction type games.

    For example, in "Bad Piggies" it doesn't notice too much; but if I focus on the hand that pans upwards during the tutorial at the start; most of the time when I tap the screen (somewhere non-interactive so as to not do anything) there is a very brief stutter. I am testing with iPhone 6 with iOS11 and iPad Pro (1st gen) with iOS11.

    However, with a reaction based game where the player taps quickly in response to something falling down the screen, the stutter is much more obvious. The stutter does not occur with rapid touches; you have to wait about 2-3 seconds between single deliberate touches.
     
    Last edited: Dec 7, 2017
  25. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    593
    Hi! Thanks for picking up the repo I once created. I guess you were also the one asking about the status in the issue section? :)
    The case number was 896252, sadly with my method of measuring they got wildly different results. I did not find the stuttering to be visible in windows builds, but I also focused on iOS, so maybe I missed it. As for windows I found that enabling Vsync gave me better results (https://forum.unity.com/threads/imp...-motion-with-unity.141417/page-2#post-2980070). The thread I linked to might also be interesting for you in general.

    Please keep me up to date if you found any solution :)
     
  26. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    With my testing the stuttering issue appears worse when vsync was enabled although is present in both cases.
     
  27. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
  28. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    593
    On iOS Unity can't control Vsync. It is always on, handled by the os as far as I know. There will be different results for android and PC with enabling disabling Vsync. As for PC, I think in general you do get better results with enabling it.
     
  29. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
  30. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    On Windows I meant with that remark; the issue is noticeably worse when vsync is enabled.

    The stuttering happens with zero instantiation; I get the same stuttering effect with zero scripting. Any continuous and fast movement is enough to see the stutter.

    In my case if I look at the profiler the only visible spikes are "WaitForTargetFPS"; all frames are way way below the budget for smooth 60fps or 120fps (since there is nothing happening apart from Unity's own built-in logic). Between 1ms and 4ms according to the profiler where the budget for 60fps is 16.67ms. The only thing that I am seeing in the profiler is inconsistently spaced "WaitForTargetFPS" calls.

    To clarify I am observing stuttering in two ways:
    1. Continuous micro-stutters with frequent major stutters.
    2. For 95% of single deliberate touches there is a brief pause.

    And, I am able to see both of these stuttering effects in every Unity game that I've tested. For example, in Hollow Knight it is hard to see the stutter on the main platform (it's there but you need a keen eye) but if you look at the faster moving foreground it's present. Also the motion of the continuous movement appears to accelerate and decelerate.

    Both of the stuttering effects are happening with a simple particle system in an otherwise empty project. If I create the exact same motion with another game engine; then neither of the stuttering issues occur.
     
  31. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Just to confirm the stupidly obvious: you are profiling in phone build and not in editor, right?
     
  32. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    Correct. I have profiled standalone builds, iphone builds and in-editor. I have even tried doing the same thing with multiple versions of Unity and the same issue occurs in all of them.

    I used the iPhone's new screen recording feature in "Bad Piggies" to record the stutter motion of the moving hand. You'll see that it's smooth and then intermittent stutters. Unfortunately you cannot see when I am tapping the screen; but I added in a few "tap stutters" by tapping a non-interactive area. The exact same stuttering at the same rate is occurring in other Unity games on this iPhone and on my iPad.

    Video download (approx 25MB) - actually download and watch otherwise it doesn't play as well.
    https://www.dropbox.com/s/oq6e82rbl67o1wq/ScreenRecording_12-08-2017 1_04 pm.MP4?dl=0

    I tried uploading the above video to YouTube but YouTube's processing made the stuttering seem a lot worse than it actually is on device. The above recording is exactly how it was on device.

    In cases where the entire background continously moves, the effect is much more visually disturbing.
     
  33. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Do you know anyone else with a different iPhone or an iPad where you could test your app? It might be a device issue.

    Can we be 100% that profiler sees everything?
     
  34. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    I am seeing the same issue on iPhone and iPad; I do not believe it to be a device issue. I am seeing the same stuttering on Unity games running on my desktop and my mac as well. The stuttering is consistent. Like I mentioned before, this issue does not occur in games made using a different game engine.

    I have no way of telling that; all I can say is that the Task Manager shows the game running with a very low 3.1% CPU (on desktop, and the stutters are there).
     
  35. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Baffling stuff. My standalone builds do well on my windows toasters. We even tested one on an iMac for release and it worked seamlessly.
    What unity version are you using? (I know the thread is about 4.2, just checking)
     
  36. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    I've tried with all the latest major versions and the latest beta.
     
  37. numberkruncher

    numberkruncher

    Joined:
    Feb 18, 2012
    Posts:
    949
    Just creating a scene with the following is enough to see the stutter; pick a particle near the bottom of the screen and keep your eye on it as it rises to see the stuttery motion.

    upload_2017-12-8_13-52-43.png
     
  38. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,923
    In future make a separate thread if the version of Unity happens to be 3+ years old. Locking this due to random chaos from different users with different problems on different versions of Unity on different hardware platforms (and different hardware) with standalone AND editor.

    In short the thread is not useful.

    Feel free to open a specific, and relevant thread to your problem, including bug report case number. There is very little chance anything will happen without you filing a bug.
     
Thread Status:
Not open for further replies.