Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Frame rate halves when tapping the display

Discussion in 'iOS and tvOS' started by Cato11, Apr 14, 2023.

  1. Cato11

    Cato11

    Joined:
    Jan 5, 2021
    Posts:
    193
    Has anyone else experienced this issue on iOS? I was previously building my game to a first gen iPhone SE and my game constantly ran at a smooth 60 FPS. I then bought an iPhone 14 Pro and since then, my game lags significantly whenever the screen is tapped. (the irony!)

    I know this because when I enable "Show Graphics HUD" in the "Settings > Developer" within iOS, I can see that the framerate literally halves from 60FPS to 30FPS every time the screen is touched. It stays that way for a second and then returns to 60FPS. It gets even weirder.. this happens even on menus when the game is not active. For example I can be on the title screen, tap somewhere and I am seeing these FPS drops. Consequently, I believe it is not caused by anything related to my game code, garbage collection, object creation etc.

    How could it be when the issue occurs so specifically whenever the screen is touched? I did some Google searches and it seems others have had similar issues since the iPhone 13, and that it may be linked to the high refresh rate displays. I tried limiting FPS to 60 FPS within the iOS settings, but it makes no difference.

    Any advice would be really appreciated. I am really hoping this can be resolved because it literally ruins the game.

    Unity Version: 2020.3.46
    Device: iPhone 14 Pro
    iOS: 16.4.1
     
  2. sfjohansson

    sfjohansson

    Joined:
    Mar 12, 2013
    Posts:
    368
  3. Cato11

    Cato11

    Joined:
    Jan 5, 2021
    Posts:
    193
  4. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    117
    This is probably an Apple side problem: https://developer.apple.com/forums/thread/695097

    At least, Unity says so (https://issuetracker.unity3d.com/issues/ios-target-fps-is-ignored-on-iphone-13-pro) and Cocos2d also have the problem. This is only happening on iPhones by the way; iPads with ProMotion are stable.

    I am "cheating" the iOS with changing target FPS as double in UnityAppController+Rendering.mm file. And also, you should enable ProMotion support in the Player settings, or set "CADisableMinimumFrameDurationOnPhone" in Info.plist to YES.

    There is a function called
    callbackFramerateChange:(int)targetFPS


    I changed it to:

    Code (CSharp):
    1.     int maxFPS = (int)[UIScreen mainScreen].maximumFramesPerSecond;
    2.     if (targetFPS <= maxFPS)
    3.         targetFPS = UnityGetTargetFPS() * 2;
    4.     if (targetFPS > maxFPS)
    5.     {
    6.         targetFPS = maxFPS;
    7.         UnitySetTargetFPS(targetFPS);
    8.         return;
    9.     }
    I really don't know if this has a downside (like high battery usage, etc), but I didn't experienced any so far. And also, this won't work if you're supporting more than 60 FPS.

    There is also a thread about similar problems with 120 FPS support in the forums: https://forum.unity.com/threads/iph...display-synchronisation-inside-unity.1276082/

    I think they're all related. But it is interesting that this doesn't happening on iPad Pros.
     
    Last edited: Apr 19, 2023
  5. Cato11

    Cato11

    Joined:
    Jan 5, 2021
    Posts:
    193
    Thank you so much for your help. I have also visited the thread that you posted, I tried everything it recommended and it did not solve the problem.

    I am trying to implement your suggestions now, I have updated the plist file as you recommend but when I try to use the above code I am getting an error:

    Use of undeclared identifier 'UnitySetTargetFPS'

    It looks like this function does not exist? Do you know how this can be resolved?


    Screenshot 2023-04-23 at 11.24.50.png
     
    Last edited: Apr 23, 2023
  6. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    117
    That's interesting. What is your Unity version? Maybe it is different with my Unity version (2021.3.20f1). I only changed the
    Code (CSharp):
    1. if (targetFPS <= maxFPS)
    2.         targetFPS = UnityGetTargetFPS() * 2;
    part actually. It was
    Code (CSharp):
    1. if (targetFPS <= 0)
    2.         targetFPS = UnityGetTargetFPS();
     
  7. Cato11

    Cato11

    Joined:
    Jan 5, 2021
    Posts:
    193
    I’m using 2020.3.46. I’ll try to deploy it without that line and see what happens. I’ll post the results here soon.

    Out if interest, did you get round to trying this fix on non-ProMotion devices?
     
  8. Cato11

    Cato11

    Joined:
    Jan 5, 2021
    Posts:
    193
    Okay so I tried it by only editing the above code, and I think you have made a big step in solving this problem! When I now deploy my build to an iPhone 14 Pro, I am no longer seeing the frame rate halve on each tap. I have investigated so many existing threads on the Unity and Apple forums, and in my experience your solution is the only one that stops the frame rate from halving. I think the key is editing the Info.plist file. Very nice!

    That being said, I am still seeing some minor stutter when I touch the display. If I turn on the " iOS Settings > Developer > Show Graphics HUD" the frame rate is no longer dropping which is good, but there still does appear to be some minor stutter, albeit much less than before and a lot less noticeable. It would be interesting to know if you're seeing the same thing?

    It did seem to disappear on one occasion, but when I rebooted the app it came back. Either way, you have achieved huge improvement so a big thank you for that. I hope others are able to find your fix.
     
    TeorikDeli likes this.
  9. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    117
    I couldn't try it yet with a non-ProMotion device; but it should be fine,
    if (targetFPS > maxFPS)
    line should work. I am glad that my solution also worked for you! Hope Apple and/or Unity solve this problem soon. I already sent a bug report to Apple, but didn't received a response yet =/
     
  10. RGAMESR

    RGAMESR

    Joined:
    Feb 10, 2017
    Posts:
    30
    i have same problem , any update on this?
     
  11. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    117
    Unity side .mm file code was changed when I last checked in 2022.2; but didn't test on a device. Maybe Apple fixed the problem in iOS 17, but I won't update to a beta yet =')

    By the way, Cato11 is right, my workaround is not working always =') This is a very annoying and serious problem; but nobody from Apple/Unity cares, which I don't really understand why.
     
  12. RGAMESR

    RGAMESR

    Joined:
    Feb 10, 2017
    Posts:
    30
    i have iphone 14 pro max and i updated to ios 17 beta , and the problem still,....
    is it from Unity or Apple?
     
  13. TeorikDeli

    TeorikDeli

    Joined:
    Apr 6, 2014
    Posts:
    117