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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Bug Cinemachine 2d follow stutter

Discussion in 'Cinemachine' started by danproduction, Feb 16, 2023.

  1. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    Hi Guys,

    I'm currently building a 2d jump and run game in Unity and I'm using Cinemachine. But unfortunately it's stuttering (in the Editor and as a build on my android Phone even more). I already tried setting aim to composer but it didnt help. Do you know what I could do? One thing i often read is decreasing the fixed timestep to 0.01, but this could cause perfomance issues, couldn't it?

    Daniel
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,874
    There can be any number of reasons for things to stutter in the camera. One of the more common ones is inconsistent use of clocks: things moving sometimes on Update, sometimes on FixedUpdate. The result is time-aliasing, where there's no "correct" time for the camera to track the target and update its position.

    It's true that setting a really small physics timestep can hide this problem, but it is a hack that comes with performance costs. A better solution is to understand how your gameobjects are moving, and to take control of the clocks. Once things are moving consistently, you'll find that the cameras become smooth.

    So, we can start with some questions:
    1. What versions of Unity and CM?
    2. Can you show the vcam inspector and a portion of your hierarchy that includes the vcam, the main camera, and the tracked object?
    3. Can you show a small video of the stutter?
    4. Do you have RigidBodies controlling the positions of your tracked objects?
     
  3. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    Version:
    editor_version.png

    cm_version.png

    Scene:
    testproject.png

    Player:
    player.png

    I hope this helps. Unfortunately i can't upload my video file. It' s just a simple project using physics for the player movement. Should I provide code?

    Daniel
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,874
    Thanks. All good so far. Now I need to see how you're moving the player.

    Since it's a simple test project, why don't you just zip it up and send it to me? (don't include the Library folder, it's huge and Unity can regenerate it).
     
  5. sabirdoktoruneri

    sabirdoktoruneri

    Joined:
    Jul 18, 2021
    Posts:
    1
    I have the same problem, I've been searching for days and can't find
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,874
    Please show your player movement script.
     
  7. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    I sent the project in privat conversation. Hope this helps.

    Daniel
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,874
    Thanks for the upload. I had a look at the project. The camera system is set up properly, the player controller scripts are correct. When I play the game in the Editor, it's perfectly smooth. When I make a build and play it on my PC, it's perfectly smooth. I cannot reproduce any jitter.
     
  9. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    Hmm. In my Editor the game is ok but if i build it on my phone (android, it should be a mobile game) then it jitters. Are there maybe any settings in the phone i can change?
     
  10. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    477
    Android is a funky beast. And Gregory tests on a powerful machine. So he's unlikely to see what you're seeing.

    Do you have any of the Jobification options for Physics2D checked? Let me know what it looks like in the Editor Project Settings under Physics2D Job Options roll down section.

    Do you have ANY 3D physics in your game? If not, remove the 3D Physics packages, all of them. They're busy even when they're not.

    Whilst you're in there, remove every package you don't need.

    How much of the tick boxes in the Layer Collision Matrix can you turn off? Turn off all that you can get away with turning off!

    Android devices are all uniquely S***, in different ways, too. For all manner of reasons. As are differing versions of the Android OS, and OEM mods etc. None of the audio plugin and synth makers focus on Android, despite it being a huge potential market, because timings are a bit of a mess on Android and its devices, despite often having many cores sitting around doing nothing.
     
  11. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    Hi Unifikation,

    this is what my Job Options look like:

    Job_Options.png

    I don't use any 3D physics in my Game. I'm sorry that i have to ask, but what do you mean by 3d physics packages? The package manager?
     
  12. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    477
    No problem! A lot of the essential stuff of Unity is hidden... I often think that's by design...

    In the Package Manager, there's various ways to see the ones you've been gifted in your project, by Unity, and the "Essential" ones, too. Almost all of both of these groups can be stripped out, and must be if you're wanting to target Android and iOS, and stay sane.

    So, yes. In the Package Manager, prepare to spend a good long while trying to find out what it's telling you about what's in your project, and what you can get rid of. Prune it to the absolute minimum.

    This will have an added benefit, rapidly decreasing your time to enter Play mode!

    Especially if you can jettison Burst, URP and all but the 2D physics.

    Speaking of 2D physics, in the screenshot, tick the "Use Multithreading" box, first one underneath the Job Options drop down. This has been a bit of a boon for me.

    Also, set your physics fixedUpdate time to 1/framerate where framerate is the most common framerate you'll target. This is likely 60 on Android. The default of 1/50th is an old remnant of a time and place (Europe in the 90's and 2000's) when PAL's 50Hz scan rate and 50fps frame rate was likely a consideration.
     
    Gregoryl likes this.
  13. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    @Unifikation
    ok so i set the fixed timestep to 1/60 and appplication.targetFramerate to 61. And i removed some packages which seemed unnecessary to me but unfortunately the jitter hasn't improved. I wasnt able to remove URP as i haven't installed this package. Here are some photos of my package manager: PM_builtin.png
    PM_inproject.png
     
    Last edited: Feb 21, 2023
  14. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    btw the profiler looks like this:
    profiler.png
    I think physics shouldn't be active here but only physics 2d. Is this
    correct?
     
  15. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    477
    Yeah, it's a long time ago, for me, but I remember that ACTUALLY getting rid of 3D physics was nowhere near as straightforward as I thought it'd be. Sorry, I can't remember exactly where I found the last remnants of it that had to be stripped out.

    Also, in your packages, you can get rid of all those monitoring packages (web request, analytics, ads etc) and the testing frame work from Unity, whilst developing.

    One more thing... latest Cinemachine is 2.9.5, and there's always little gremlins that Gregory is getting rid of in each update.

    And... one more thing... have you checked that "use multithreading" under 2D physics? Android devices have a lot of cores, usually, so this is generally a good thing.

    But I think you're right, that memory usage, followed by a dump/cleanup is very likely causing your stutter. Just gotta track down where that 3d physics is...

    Are you using Volumes for anything?
     
  16. danproduction

    danproduction

    Joined:
    May 29, 2021
    Posts:
    8
    @Unifikation @Gregoryl

    I was able to fix it. I found out that my phone was running at 120 fps while I built my Game at 60 fps . Now everything is butter smooth. Thank you Unifikation and Gregoryl very very much for your help!

    Daniel
     
    sabirdoktoruneri and Gregoryl like this.