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:
function Awake() {
Application.targetFrameRate = 60;
}
function Update() {
transform.position.z += 2 * Time.smoothDeltaTime;
}
(I have also tried vsync on/off, LateUpdate, FixedUpdate, average of smoothDeltaTime and deltaTime, Mathf.Lerp, etc. No luck!)
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.
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.
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.
@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?
@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.
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.
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).
@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)
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.
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?
My problem is not “FPS drops” and not limited to iOS7.
If targetFPS is set to 60, FPS is consistent at 60 fps but there is stuttering.
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?
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?)
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.
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.