Search Unity

Bug Freezing on PlayMode after adding cinemachine

Discussion in 'Cinemachine' started by Niter88, Nov 29, 2022.

  1. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    Hello. I have an Android project, Unity is 2021.3.10f1 (LTS) running on a 11# gen i7. The project runs at maximum framerate on any android device.

    So I've added cinemachine(2.8.9) to support camera smoothing, all configured and working.

    Then I hit playmode, everything works fine, then I sart moving the player object on the local Z axis, sometimes the player get behind camera view and it needs to reposition, when the player hits the "red" corners of target view, PlayMode Freezes hard.

    Problem is, it freezes for 5 to 10 seconds on an i7, but it has to run on old android devices (the ones with 2gb ram). It was running properly just before cinemachine, I fear that something very bad happen when I upload it to the store.

    1- Can anyone reproduce that? Is this known?

    2- How to fix it?

    3- Is it PlayMode related or will it affect production?
     
  2. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    I forgot to mention, it's not this bug. I have the profiler disabled.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    We have not seen such an issue before. We don't have any known issues entering playmode. Are you able to upload a repro project that shows this?
     
    Niter88 likes this.
  4. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    I'm still testing it, it doesn't seem to affect production. I will need to go outside and drive to make more solid testing (it uses GPS as position)

    I've changed the configs so that the Z position follow is more aggressive, that way I've reduced the chances of getting the player object on the screen corners.

    The setup is: I've added a default brain and virtual camera.
    Gone to the virtual camera, put the player as the look at and a position behind it to be the follow.
    Then I altered:

    FOV to 60
    Body to Orbital Transposer with X and Z damping on 3 and Y damping on 1 (Yaw is 0)
    Aim to Composer, vertical and horizontal damping are at 0.5

    Entered on play mode:
    Moved stayed on the Game window and kept sliding the value on the player Transform position
    Moved the player quickly on the X axis (fine)
    Moved the player at medium speeds on the Z axis (fine)
    Move the player quickly on the Z axis, moving quickly back and forth (Unity freezes from 5 to 20 seconds, other programs working fine)

    I've got to this while trying to simulate bad GPS signal, when your GPS location crazily moves and rotates a lot.
    Sliding it above 50m/s on Z axis seem to trigger the freezing on the configs above. I am respecting floating precision.
    I expected that cinemachine would not freeze like that even at high speed, specially since it's updating on the late update function.

    PS: any slight constant movement on the camera drops FPS from average 500 to 75/90. is this also expected?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Cinemachine really doesn't care whether the camera is moving or not, it's the same code path. Are you sure that it's Cinemachine that's freezing?

    Can you post pictures of your Cinemachine vcam inspector, the CMBrain inspector, and also the hierarchy showing the vcam, the main camera, and the camera target?
     
    Niter88 likes this.
  6. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    Not sure what is freezing. All other components are inactive on playmode since they need to receive events in order to start.

    Here are the pictures with the new values. Changing the Z damping and the Look variables seems to have avoided the freezing since it doesn't get to the corners anymore. I don't get why I was getting that behavior before thou

    PS: some names are redacted, sorry



     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Sorry, but I don't know what you mean by the "corners".

    Can you give some idea about the geometry? A debug output of the positions of the vcam, the LookAt target, and the Follow target - during the freeze - would be helpful.
     
  8. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    Ok, I can't show a print of the project and I think it will be better with illustrations anyway.

    Let's say we have a character named Tom. Tom has a camera that he can position around him, he can chose to rotate it spherically around him and change it's distance to him, the camera follows that position. The camera also always stare at Tom's chest.

    Tom has positioned the camera behind him, staring at his back. The camera is at a higher position than Tom and also rotates to face roughly the same direction as Tom.


    The Color overlay on Tom's camera means the current Aim Zones for his virtual camera.

    Let's say that Tom runs backwards to the right corner of the screen. he will run on the 1Direction (at a given s speed) and by the end of the frame he will end up on the 1Position. The camera follows along and recenters on Tom.

    Now let's say that Tom dodges even faster to the bottom of the screen, let's use 2Dir for that. He dodges at a higher speed (maybe s * 4) and by the end of the frame he is supposed to be after 2Pos, a little further on the 2Direction.

    But something happen and the game freezes showing Tom stuck at the 2Pos. At this moment Unity is frozen, can't exit playmode, can't edit Tom's variables, clicking on a variable's field will still highlight it in blue after a delay. After 5 to 20 seconds the camera finally moves, correcting it's trajectory to show Tom at the center of the screen.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thanks for the description.

    That freeze is not something we've seen before, and without a repro project in hand I can only guess at the cause.

    Can you try moving the vcam out of the MCameraHolder hierarchy? Normally, vcams should not be parents or children of the objects they are tracking. Does that change anything?
     
    Niter88 likes this.
  10. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    I was thinking about that. I will surely do it. With the new configs I am using right now I am not able to reproduce the error anymore, it lies only on my git. I think that problem can only be reproduced with a precise set of settings plus the camera position.

    I will try and see if anything changes on the next few days.
    Anyway thanks for the help @Gregoryl
     
    Gregoryl likes this.