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.

Bug UI Jitters when camera follows the player's character

Discussion in 'Cinemachine' started by UdristeDavid, Feb 28, 2023.

  1. UdristeDavid

    UdristeDavid

    Joined:
    Nov 6, 2021
    Posts:
    9
    Hi there! I'm hoping to get some help with an issue I'm experiencing in Unity. I'm struggling with jittery UI when my Cinemachine camera follows the player's character. This has been a problem in every project I've worked on since starting game development over a year ago, and I'm at a loss for how to fix it.

    I've attached a video to show the problem, as well as some images of my camera and canvas settings. The jitter is even more noticeable on lower resolutions. I've scoured the internet for solutions, but nothing seems to be working for me. If you need any more information, I'd be happy to provide it.

    PS: The movement of the character is happening in FixedUpdate.

    https://i.imgur.com/gRbkjS7.png

     
  2. UdristeDavid

    UdristeDavid

    Joined:
    Nov 6, 2021
    Posts:
    9
  3. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hi
    Could you send me a repro project? I am going to investigate.
     
  4. UdristeDavid

    UdristeDavid

    Joined:
    Nov 6, 2021
    Posts:
    9
    Of course and thank you. I also want to mention that the jitter is not only visible on the UI but also on "normal" game objects that are not part of a canvas. I added two of them in the scene so that you can see what I mean. I should've specified in the original post but I thought that was no longer happening.

    https://drive.google.com/file/d/1u3ybPrnFMRobLDQH0Xjo8971WUGKLu7n/view?usp=sharing

    Same issue on another project, last year:
     
  5. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Have you tried setting Interpolation on your RigidBody?
    Interpolate.png

    It seems to fix the issue on my side.

    Usually jitters are caused by different update loops not being in sync. When you enable interpolation of the RigidBody, then the animation will be in applied in sync with the Update clock.
     
    Gregoryl likes this.
  6. UdristeDavid

    UdristeDavid

    Joined:
    Nov 6, 2021
    Posts:
    9
    This is one of the first things I tried, but it doesn't change anything for me.
     
  7. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    The jittery scene objects are fixed by turning interpolation on.

    But you are right, the UI jitters regardless. This jitter is not caused by Cinemachine. If I disable CinemachineBrain and attach the camera to the player directly, the jitter persists. This indicates that Cinemachine is not the culprit.

    The UI jitter seems to be caused by Pixel Perfect Camera. When I turn it off, there is no jitter on the UI.
    I've seen some forum posts regarding this (example).
    It may have been resolved by a newer version. Can you try updating 2D Pixel Perfect to version 5 or above?

    You could also try asking the 2D team's forum. They may be able to help you fix the UI jitter.
     
    Gregoryl likes this.
  8. UdristeDavid

    UdristeDavid

    Joined:
    Nov 6, 2021
    Posts:
    9
    You're right that removing the Pixel Perfect Camera solved the issue. And wow, upgrading the demo project to the latest LTS version made it so that the jitter goes away even with the Pixel Perfect Camera on. (I can only assume that this is because in the version I was using, the Pixel Perfect Camera from the URP was still in an experimental state.) However, for some reason, the jitter is still visible on the cursor. I tried changing when I update its position in the script to LateUpdate and FixedUpdate, but that didn't solve the problem.

    The thing is that, since my game art is pixel art, the Pixel Perfect Camera makes total sense. And having the stretch fill function is really nice to make sure the UI doesn't expand on the black bars when the game's window size is changed.

    Do you have any thoughts on that? Having the UI fixed is awesome, but it would be great to fix the cursor too.

    And if you don't mind one more question: The project I sent you is, of course, a demo project, but do you think it's safe to upgrade my main project to the newest LTS version (since it seems to solve my issue)? I'm not sure if that would mess up my scripts, shaders, or anything else.
     
    Yuchen_Chang likes this.
  9. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I'd make a backup, and then try upgrading. I don't think you'll have a problem, but better safe than sorry. ;)

    Not really. I'd ask on the 2D team's forum.
     
  10. UdristeDavid

    UdristeDavid

    Joined:
    Nov 6, 2021
    Posts:
    9
    Alright. Thank you very much!