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

Bug iPhone 13 Pro 120hz, something is wrong with display synchronisation inside Unity

Discussion in 'iOS and tvOS' started by PavelDoGreat, May 2, 2022.

  1. unity_rol

    unity_rol

    Unity Technologies

    Joined:
    Nov 4, 2020
    Posts:
    8
    Good to hear. Apologies for how the submission has been handled again, and thank you for raising and helping with the display link issue.
     
  2. Cato11

    Cato11

    Joined:
    Jan 5, 2021
    Posts:
    193
    I recently created a thread about this, not realising this thread already existed. I am seeing my frame rate halve from 60 FPS to 30 FPS whenever I touch the display of my iPhone 14 Pro.

    Unity: 2020.3.46
    iOS: 16.4.1
    Device: iPhone 14 Pro

    Please tell me this can be resolved for 2020.3? I have been building my game for two years in Unity 2020 so the idea of having to migrate it to 2021 or 2022 to fix this issue worries me greatly.

    __

    I tried changing both:

    #define ENABLE_DISPLAY_LINK_PAUSING 0
    #define ENABLE_RUNLOOP_ACCEPT_INPUT 0

    Also tried the suggestion by Feelnside and it makes no difference. All of this was done with a target frame rate of 60 FPS. I tried switching it to 120 FPS and repeating these tweaks, but it seems to have made no difference.

    It's really weird because the issue of screen taps causing frame drops does seem to disappear for a very short time period near the start of the game, but then it just reappears and persists as a problem.
     
    Last edited: Apr 16, 2023
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    The final 2020 LTS is out and both
    ENABLE_DISPLAY_LINK_PAUSING
    and
    ENABLE_RUNLOOP_ACCEPT_INPUT

    are still set to 1.

    Should I be changing them to 0 manually?
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    Even on 2021 these are still set to 1, any updates @Alexey ?
     
  5. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    > The final 2020 LTS is out and both
    > Even on 2021 these are still set to 1,

    yeah, this was NOT backported to 2020 on purpose (too close to final LTS hence quite risky) and 2021 was hit by internal issues, but we really want to push it there
    I would say setting both to zero manually should work and is the way to go for now if you are stuck on pre-2022
     
    AcidArrow likes this.
  6. anon8008135

    anon8008135

    Joined:
    Jul 7, 2023
    Posts:
    145
    Sleuthed through a bunch of threads related to stuttering related to framerate dropping on tap. After pushing a bunch of buttons, the only semi-consistent method I've found to get iOS apps to run at the targeted frame rate set by Application.targetFrameRate is setting it via a listener subscribed to an event invoked on TouchPhase.began, and keeping a finger stationary on the display. No moving allowed. I only tested setting the framerate to 120, but it should probably be the same for setting target framerate to 60. Set the bools in info.plist to "Yes" to enable 120 fps. Modifying the flags in rendering.mm doesn't affect the results.

    Using a second finger to initiate a new tap will not tank the fps, most of the time. The contact pressure for the first tap while holding has to be constant for the most part it seems or the event doesn't fire I'm assuming. I pinched my phone while tapping away with another finger. If it doesn't work restarting your app will usually produce the desired behavior.

    You can switch fingers, but there has to be one finger on the screen the entire time for the framerate not to drop. Tapping the display without a stationary finger on it will cause the fps hiccup.

    Sometimes the framerate will drop to 60 and get locked there for a while, seems to be triggered by how you end the touch. Reloading the scene via LoadSceneAsync will unlock it though. Or just tap the screen until it does unlock.

    Setting Application.targetFrameRate in Update() did not do anything for me, which isn't that surprising. Event system probably works since it's firing with the input handler.

    Obviously can't design a game around a finger being stationary on the screen the entire time, but at least there's some improvement. I implemented TeriokDeli's hack from https://forum.unity.com/threads/frame-rate-halves-when-tapping-the-display.1425075/#post-8959434, but it didn't really make the motion smoother, even when all profilers showed 16.66-16.68 ms frametimes. Maybe if there was a way to fire a virtual touch constantly as a hack to emulate a finger always on screen, since Apple isn't providing any solutions, and the problem doesn't seem to be an engine problem since other engine users are reporting the same problem.

    Invoking the delegate unconditionally doesn't work, as in it will not negate framerate hiccups. Once again, the only method I've found to semi-consistently get rid of the hiccups is having a stationary finger on the screen.

    Hopefully these findings help someone find the root cause of this ridiculous problem and/or a solution so I can stop crying at my game stuttering and doubting my code...

    iOS 16.5, Unity 2021.3.23f1, iPhone14 Pro
     
    Unifikation likes this.
  7. anon8008135

    anon8008135

    Joined:
    Jul 7, 2023
    Posts:
    145
    Actually nvm, you don't have to use an event system to set Application.targetFrameRate at all. Just having the stationary finger on the screen will negate the hiccups. Tested on a blank project.
     
    Unifikation likes this.
  8. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,043
    Has this been sufficiently resolved that we don't have to do anything on newer Unity versions and can rest assured that we'll get stable (higher than 60fps) frame rates in VisionOS?

    or do we need to do something to get stable, higher than 60fps frame rates for iOS/iPadOS/VisionOS/MacOS?
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    This is what we did, no problems so far with our public build after roughly a month after release.
     
  10. anon8008135

    anon8008135

    Joined:
    Jul 7, 2023
    Posts:
    145
    @AcidArrow does your game not exhibit frame rate hiccups when tapping (assuming you’re building to iOS).
     
  11. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    I haven't noticed that happening lately, but:

    1. Hitching on tap used to happen on earlier iOS devices for me. I always assumed it was a combination of the OS, Unity and the game (we do some raycasts and pathfinding on tap), that would push us over the frame budget. Not sure if my assumption was correct and if we are talking about the same thing.

    2. My current main testing device is a iPhone 13 Pro Max and our game is intended to run 60fps on a 6S, so the 13 isn't really sweating, even with the bigger resolution and 120fps, so there's probably enough room left for tap related spikes.

    The only spikes I consistently see a lot of, and I haven't really found a way to get rid of are the "omg I just saw a new shader", where regardless of the device there is always a hitch, and the prewarm methods Unity provides flat out don't work.
     
  12. anon8008135

    anon8008135

    Joined:
    Jul 7, 2023
    Posts:
    145
    That's interesting, seems like all ProMotion iPhones have this problem from what I've seen online, so I'm surprised your testing device doesn't. I don't have access to another ProMotion device so my sample size is obviously only one, but it seems like frametimes spiking on tap is a very consistent behavior. You can verify it easily by building a blank project, no scripts and assets at all and enabling "Show Graphics HUD" in the developer settings on the iPhone. It'll show a spike in frametime every new tap, unless as I've noted above you have a stationary finger on the screen prior to tapping. If your device doesn't exhibit this behavior, then I guess it could be a hardware defect and would make sense why Apple has said nothing regarding this issue lol.
     
  13. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,043
    Pokemon Go has a 120fps mode from the iPhone 13 onwards. And is made with Unity, and apparently the most popular of all iOS based Unity made games.

    Could Unity at least inform us of how they achieved this, and whether or not it's stable at 120fps?
     
  14. anon8008135

    anon8008135

    Joined:
    Jul 7, 2023
    Posts:
    145
    Some other findings based on Unity game templates:

    For the "Runner Game" template, jacking the fps up to 120 will understandably make the phone hot so thermal throttling will kick in, and tapping the screen will no longer affect frametimes. When the phone is cool though, tapping the screen will affect frametimes (negatively). In case it wasn't clear, I switched the platform for the template to iOS and ran it on my iPhone.

    For the "FPS Microgame" template, it is unable to reach 120, but will reach 100 fps on my iPhone 14 Pro. Interestingly enough, tapping does not affect the frametimes. I'm guessing it's because the taps are getting mapped to mouse events instead? Obviously that template does not incorporate touch controls out of the box. How you handle inputs might be a key to sidestepping frametime issues on tap. I don't mean the differing Unity Input Systems (Old and New). That was controlled in my experiments since I built all the templates with "Active Input Handling" set to the default Input Manger (Old).

    Unfortunately, I don't know what magic setting/feature the "FPS Microgame" template is using, or not using, that is enabling it to not run into frametime issues on tap. Maybe the fact that it is unable to reach the targetFrameRate of 120 has something to do with it.
     
    Unifikation likes this.