Author Topic: Label movement stutter/slowness on iOS without FPS drop  (Read 5189 times)

taikuukaits

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Label movement stutter/slowness on iOS without FPS drop
« on: May 22, 2015, 05:06:48 PM »
I realize this might be hard to help with without knowing all the details but I figured I would try anyway, I can provide any and all information or a video demonstrating or the project itself.

The problem is I have an NGUI label I want to slide around the screen but the moment it moves, it looks 'slow' and 'stutters' on iOS (6 Plus). But the rest of the game looks fine, there is no slowdown of particle systems [and besides one of them there is nothing else moving].

I reduced the draw calls to 6 (maybe that is still too many? but 1 is font, 1 is sprites, 1 is buttons and the rest are ordered calls of those), put the moving label in its own panel, even tried disabling everything else but still when the label moves it is slow. (But again the rest of the game is perfectly smooth). All anchors are set to update on start.

 I must be doing something wrong as I have seen way more complicated games with perfectly smooth animating ui elements. I am really confused and hoping someone can help as I have an extremely simple scene (at least imo, only a few labels and sprites) and am disappointed even this small demo isn't performant on mobile devices.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Label movement stutter/slowness on iOS without FPS drop
« Reply #1 on: May 26, 2015, 02:35:33 PM »
Obvious question first -- have you tried profiling it? If the game runs fine, then it's likely not NGUI. If NGUI was slowing down something, then the whole game would be slow, not just your label. How are you moving it? Post some code.

taikuukaits

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Label movement stutter/slowness on iOS without FPS drop
« Reply #2 on: May 26, 2015, 04:27:31 PM »
Hey Aren! Thanks for helping!!!

So I have profiled it on the desktop, wasn't helpful obviously - I am trying to profile on iOS but am having trouble attaching Unity  to Xcode. I will profile on iOS and get back to you as soon as I can.

I must be doing something wrong. NGUI is the only thing "slow". The rest of the game runs fine. It also runs "slow" on scroll view drag.

But anyway, for the label: I have UIRoot -> LabelPanel -> Sprite -> Label. And I am moving the sprite. When the sprite is created it has a TweenScale. Nothing else in that panel. Nothing else moving.

I move with this code in update (on the Sprite), basically moving until I am off the screen.

  1. float left = -myPanel.GetWindowSize().x / 2f;
  2. float right = myPanel.GetWindowSize().x / 2f;
  3. float top = -myPanel.GetWindowSize().y / 2f;
  4. float bot = myPanel.GetWindowSize().y / 2f;
  5.  
  6. float myleft = transform.localPosition.x - (widget.localSize.x / 2f);
  7. float myright = transform.localPosition.x + (widget.localSize.x / 2f);
  8. float mytop = transform.localPosition.y - (widget.localSize.y / 2f);
  9. float mybot = transform.localPosition.y + (widget.localSize.y / 2f);
  10.  
  11. bool offLeft = myright < left;
  12. bool offRight = myleft > right;
  13. bool offTop = mybot < top;
  14. bool offBot = mytop > bot;
  15.  
  16. if (offLeft || offRight || offTop || offBot){
  17.     Destroy(gameObject);
  18. }
  19.                
  20. transform.position = new Vector3(transform.position.x + velocity.x * Time.deltaTime, transform.position.y + velocity.y * Time.deltaTime, transform.position.z + velocity.z * Time.deltaTime);
  21.  

And velocity is
  1. float speed = 4.0f;
  2. velocity = transform.up * speed; // Or other direction like transform.down
  3.  

taikuukaits

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Label movement stutter/slowness on iOS without FPS drop
« Reply #3 on: May 27, 2015, 12:41:25 PM »
So I fixed my issue and wanted to share with the class.

After creating a new scene and NGUI -> New 2DRoot -> New Panel -> New Label, I was able to recreate the same stuttering. So then I created a 3D sphere and gave them both the same behavior (with slightly tweaked settings) to move and then reset to center. They both stuttered. So even though my main game's particles weren't stuttering it seems the rest of Unity was. So I had a new angle to research, Unity iOS stuttering.

Then I came across this forum post: http://forum.unity3d.com/threads/stuttering-issue-on-unity-4-2.203552/page-2

And specifically followed Trungdv's suggestion:

Quote
- Open QualitySettings in Project Settings, set level to "Fastest". (I just unchecked all but fastest for iOS)
- Set target frame to 60 in code.  (Using Application.targetFrameRate = 60; in some scripts start)
- Open PlayerSettings, in "Other Settings":
+ Make "TargetResolution" to be "Auto (Best Performance)".
+ Make "Graphics Level" from "Auto" to "OpenGL ES 3.0".

And everything is as smooth as butter.

I haven't tried using just some of the settings and seeing if there is a specific one that fixes the problem so a bit more research is needed, but it is working for me now.

taikuukaits

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Label movement stutter/slowness on iOS without FPS drop
« Reply #4 on: May 27, 2015, 12:46:08 PM »
Already have an update.

Looks like targetFrameRate is the most important (or at least without it the game is not smooth and with it, it is smooth). I did not try re-enabling the other settings and seeing if only this fixes it, as it is working and I am not going to mess with it ;D

I figured this out as I had accidentally unchecked the start scene (which set the targetFrameRate) and it was still choppy, but including it and the frame rate set, and it is smooth. So perhaps only frame rate matters.

Here is my script to set the frame rate (it is simple but why not provide it). It is on an empty GO in the first scene of my game:

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class FramerateSetter : MonoBehaviour {
  5.  
  6.         // Use this for initialization
  7.         void Start () {
  8.                 Application.targetFrameRate = 60;
  9.        
  10.         }
  11.        
  12.         // Update is called once per frame
  13.         void Update () {
  14.        
  15.         }
  16. }
  17.