Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Cinemachine 2D Camera is inconsistent based on Brain Update Method

Discussion in 'Cinemachine' started by Tosatsu, Sep 13, 2018.

  1. Tosatsu

    Tosatsu

    Joined:
    Sep 4, 2014
    Posts:
    11
    Hello everyone, quite a bit of searching has led me nowhere so here I am.

    TL;DR using Smart Update causes a snap to center of the Follow target, when it switches from Fixed Update to Late Update in the Virtual Camera, and vice versa, when using a Dead Zone.

    My issue is, telling the Brain to work in Fixed Update seems to not set the virtual cameras the same. In the top right corner of the Virtual Camera they still report to be working in Late Update. Also, the Framing Transposer no longer works, and the guiding "dot" is always centered. I'm guessing it's actually working in Fixed Update, as it seems to be in sync with the generic Jitter the physics character has, and the Transposer breaks because the update occurs same frame, and it can't calculate it's framing? just guessing.

    Setting Brain to Late Update seems to keep the Virtual Cameras in Late Update, kind of expected, but Jitter occurs because of Late Update vs. Fixed Update. Background is silky smooth though, well as expected. But background Jitter is not that bad overall and I need the character to be followed consistently.

    Setting Brain to Smart Update caused me to notice all these details, as it was the default from the beginning. What happens is it actually shows the virtual cameras as using Fixed Update, until movement stops. Give it a bit of time and it jumps to Late Update, until the guiding "dot" leaves the bounds area, causing the camera to move again. This is not the issue, I kind of expect this. The issue is, WHEN it jumps to Late Update it resets to the Center, causing it to jump if it was closer to the edge of the dead zone.

    The "Player" object followed contains multiple scripts related to various functionalities, but the movement/velocity changes only occur in FixedUpdate.
    Rigidbody is not set to Interpolate, and that doesn't change the behavior. Kind of changes the jitter though I can't really tell. It's still there with Late Update.

    My main thought was that, based on what I read, the cinemachine might be confused as it's not a clean hierarchy containing multiple scripts under the Player, so I expected specifying Fixed Update to fix this, but it seems to break the Framing Transposer. The follow is smooth, but Framing Transposer no longer does anything in regards to damping and dead zone. It's as if they are set to 0...

    My apologies if I did not explain this properly, I just started working with Cinemachine.


    Fixed Update:

    Virtual Camera reports Late Update:

    I even went full insanity mode trying random on offs for all the settings, trying to modify via script, nothing worked sadly. :(

    To note, using unity 2018.2.6, Cinemachine 2.2.7
     
    Last edited: Sep 13, 2018
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,532
    This is very strange behaviour. I'd like to look at it more closely. Is there any chance that you could isolate it in a small project and send it to me?
     
  3. Tosatsu

    Tosatsu

    Joined:
    Sep 4, 2014
    Posts:
    11
    Sure thing Gregoryl. So the project is a 2D platformer. I stripped down Everything besides basic left right movement. I know setting the velocity is not the best but it gave consistent feel :p

    https://drive.google.com/open?id=17vxXt5PQaVVJ69FNaDp2ID4NWbqNiGI7

    How to reproduce:
    Use A/D/Arrow Keys, input is simple code straightforward.
    Under the Main Camera, start with Smart Update:
    - behavior is pretty consistent, but leaving the "player" not moving for a while, and moving inside the dead zone will cause the Virtual Camera to switch to "Late Update", and it SNAPS to the center of the dead zone, kind of "resetting" it.
    Late Update:
    - works kind of expected, jitter is caused by my physics shenanigans and I take the blame, any thoughts on optimizing it somehow?
    Fixed Update:
    - it follows the "Player", but the Dead Zone no longer works. It's as if it's set to 0.

    Gregoryl, if it helps I can jump on a screen share if reproducing doesn't work or you need to see something else. Thanks for your time and help, it's greatly appreciated :)

    Update: I tested building my project, build is standalone Win x32. The Brain is set to Smart yet it behaves as if it's always using Late Update > Physics jitter.
     
    Last edited: Sep 14, 2018
  4. Tosatsu

    Tosatsu

    Joined:
    Sep 4, 2014
    Posts:
    11
    @Gregoryl
    I did more testing, and I managed to get it working butter rich smooth by using Interpolation on the main character. Funny thing is, I tried Interpolation/Extrapolation before creating this thread, and it did nothing. It did nothing today too, a few tries in it started... working... I just don't even at this point.
    Extrapolation is not as consistent, but I will further test things out, including some control ideas for fixed time steps, with high/low frame rate scenarios.
    The particular "snap" issue remains ONLY if Interpolation is OFF. It seems that Interpolation ON keeps the virtual camera in LATE UPDATE all the time, interestingly.
    Maybe that snap should still be investigated, it might not be saving the dead zone position when it switches the Update type dynamically in Smart Update.
    I hope my testing helps you guys iron out stuff.
    If i'm stupidly doing mistakes and breaking stuff... sorry, please let me know! :D
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,532
    Thanks for uploading the project. Sorry for the delay in responding, I was travelling.

    If you set the player to interpolate, CM set to smart will update the camera in LateUpdate. This is expected and correct behaviour, due to the way interpolation works. If you force the brain to update on FixedUpdate when the target is interpolated, you will get jitter. This is probably what was happening when you tried it before.

    I am altogether unable to reproduce the "snap" issue that you mention. When I leave the player still for a while, it does not snap to the center of the dead zone.

    However, when in Fixed update, the damping was indeed ignored and the target snapped to the center of the dead zone. This is a known issue in CM 2.2.7 and has been fixed in the upcoming 2.2.8 release.

    I'm glad that your issue was resolved with interpolation. This is the recommended solution. Thanks for your patience and your detective work :D
     
  6. Tosatsu

    Tosatsu

    Joined:
    Sep 4, 2014
    Posts:
    11
    @Gregoryl so the snap issue remains but only pertaining to the following scenario:
    Brain set to Smart, follow target not interpolating. We know this is "bad" per say, and we have a fix, but:
    - player moves, hits edge, virtual camera switches to Fixed Update as it recognizes the update type.
    - wait around in the dead zone, sit still or move just a bit. make sure not to hit the edges of the dead zone. wait, more if needed ,move a bit. at one point, it changes to Late Update under the virtual camera.
    - the switch, do you know if it is expected? Does it "hear" a different Late Update listener somewhere? :O
    - in my case, this "switch" causes the snap to center instead of pertaining the position in the dead zone box

    Sorry if I bothered you again Gregoryl, but for example, if I sit on a moving platform, that has no interpolation(no rigidbody) and the platform child's my player to make it "stick", the smart brain goes all into fixed update, and gives the snap a chance to occur.

    I will make a video tomorrow, maybe i'm being stupid, but IF it's a bug, I want to help you guys remove it :D

    As for using just Late or just Fixed, now I have fully learned how the execution cycle works and what to expect and they work perfectly as expected.
    In my eyes, it looks like when the virtual camera switches the update methods, it looses the dead zone value and forgets where it was prior. Let me know how you would like to proceed.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,532
    Brain is in smart, player is not interpolating.
    vcam remains in FixedUpdate. I can't get it to display LateUpdate.
    Moving to the edge of the dead zone, then waiting.
    vcam does not switch to LateUpdate.
    I see no snap issue.

    upload_2018-9-17_16-46-47.png
     
  8. Tosatsu

    Tosatsu

    Joined:
    Sep 4, 2014
    Posts:
    11
    So it is very hard to reproduce. Funny thing is it happened once, took the first screenshot, and I had to move, wait, move, without hitting the dead zone, since that we know keeps it in Fixed Update.
    First is fixed update, second is the jump the Late Update. I'm a bit to the right from the center because Right key > Jumps to middle > moves a bit :p
    @Gregoryl hope this helps. Let me know xD
    In the end, I guess the virtual cam has no reason to be in late update, or do the snap.
    Quick detail. Moving, mostly it seems after stopping, causes the snap, and only inside the dead zone.

    1.PNG 2.PNG