Search Unity

Use Virtual Camera In My Game Scene, but it always causes Scene changes, how to stop that?

Discussion in 'Cinemachine' started by TefarMain, Apr 13, 2020.

  1. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    The git diff like this:
    WechatIMG83.png
    the virtual camera change its m_LocalRotation auto , and it always happen, it causes my scene need save everytime, did anyone the same problem with me, and told me how to stop it ?
     
  2. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Can you show me the inspector for the vcam that's doing this?
     
  4. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    this is the scene Hierarchy and one of VCam inspector.
    截屏2020-04-14 下午7.43.12.png 截屏2020-04-14 下午7.43.23.png
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    hmmm... looks like a precision issue. Can I see the inspector for the target group?
     
  6. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    the group contains two position. Is this issue already known before?
    截屏2020-04-14 下午8.05.14.png 截屏2020-04-14 下午8.05.23.png 截屏2020-04-14 下午8.05.37.png
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    It's not a known issue. The CM scripts are ExecuteAlways and so they are running even in EditMode. If your group member positions are fluctuating then they will cause the vcam targeting the group to rotate slightly. Is your SummonPosition script ExecuteAlways?
     
  8. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    截屏2020-04-14 下午8.12.46.png

    nope , it is a emm.. normal class. and the two position is settled, will not change all the time.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Well, then I don't know why it's flickering like that. Can you create a small demo project where this happens and PM it to me?
     
  10. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    I have create a new scene 'CM Scene' , create two Empty GameObject for TargetGroup1 , and save the scene. But when I click something in Hierarchy like CM vcam1, the Scene changed and show * marker.it is weird , please look and help me to solve the issue. Many Thanks. 截屏2020-04-14 下午8.26.55.png
     

    Attached Files:

  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Before you do that, maybe you could try with latest CM 2.6.0-preview release? Let me know if the issue is still present with that release.
     
  12. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    I try it with CM 2.6.0-preview.2, but the issue still exist.
     
  13. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Yes, I was wondering if there might be a connection. In fact his issue did get fixed; he sent me a test project in a private thread. It turns out that his problem is solved in CM 2.6.0-preview.3 (which isn't released yet).

    If you'd like to wait for that release, that's fine. If you need a fix now and want to verify that it's the same issue, I could instruct you on how to patch CM 2.5.0 to test it out. Let me know.
     
  15. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    OK, what I just need to do is try to verify that if it's the same issue right? And if it is the same issue, I just need wait CM2.6.0-preview.3 publish.
    I also want to know how to patch CM 2.5.0 to test it out, please instruct me. Many Thanks!
    截屏2020-04-16 上午8.50.13.png
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    You can patch CM 2.5.0 by first locating it in the package cache (an easy way to do that is to use the Unity inspector: select "Edit Script" on one of the Cinemachine behaviours and it will take you there).

    Find CinemachineComposer.cs, and al line 217 add this line:
    Code (CSharp):
    1.                 rigOrientation = Quaternion.LookRotation(
    2.                     rigOrientation * Vector3.forward, curState.ReferenceUp);
    3.  
    so that the new code looks like this:

    Code (CSharp):
    1.             if (deltaTime < 0 || !VirtualCamera.PreviousStateIsValid)
    2.             {
    3.                 // No damping, just snap to central bounds, skipping the soft zone
    4.                 rigOrientation = Quaternion.LookRotation(
    5.                     rigOrientation * Vector3.forward, curState.ReferenceUp);
    6.                 Rect rect = mCache.mFovSoftGuideRect;
    7.                 if (m_CenterOnActivate)
    8.                     rect = new Rect(rect.center, Vector2.zero); // Force to center
    9.                 RotateToScreenBounds(
    10.                     ref curState, rect, curState.ReferenceLookAt,
    11.                     ref rigOrientation, mCache.mFov, mCache.mFovH, -1);
    12.             }
    13.  
    The caveat is that this patch is machine-specific, and will not be shared with other devs on your project unless they also make the patch.

    If you try it, please let me know whether it fixes your issue.
     
  17. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    OK, I have tried it, but didn't fixed, the m_LocalRotation also changes a bit. WX20200416-101936@2x.png
    WX20200416-101707@2x.png
     
  18. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    Hi did u receive my reply
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Yes I did, but I was sleeping :)

    At this point, the only thing I can think to do about this is for you to reproduce this issue in a small demo project that I can look at and debug.
     
  20. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
  22. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    [1]Issue Description :CM VirtualCamera changes its m_localRotation value a bit all the time, it causes my Scene changes.

    [2]Issue Path: I upload a sample project, open it with Unity, open SampleScene, then you only need click CM vcam1 which in the Hierarchy. NOW you will SEE the SampleScene end with a marker * , means it has changed.(or click Play button to run the game, then stop it, u will also see the same result.)

    [3]Unity Version: 2019.3.4f1

    [4]CM Version: 2.5.0 release

    [5]If u find the way of fixing it, Please call me!! Thank You!!
     

    Attached Files:

  23. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    Go go go !!! u r the best!!
     
  24. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    Watch this Image, the SampleScene doesn't change. 截屏2020-04-16 下午8.45.53.png

    But when I click CM vcam1 , the Sample Scene changes right now.
    截屏2020-04-16 下午8.45.59.png
    It is easy to show the issue. you can try this path.
     
  25. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Yes, I can repro. Thanks for the upload! I'll look at it later today and try to figure out what's going on.
     
  26. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    Thank u 3 thousands!!
     
  27. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    I looked at the scene, and found the issue. Unfortunately, I don't think it's the same issue as the one at the beginning of this thread.

    In your test project, the scene is marked dirty if you click on the vcam to display the inspector. This is caused by the inspector wanting to show the game view composer guides. To do this it must repaint the game view, and since Unity 2019.1, the way to do this is to mark a game object dirty (even if it's not) and request a repaint. So the * marker on the scene is not telling the truth. You can prove this by saving the scene and then comparing it to the original. There is no difference.

    So that really sucks. The good news is that there is another API call to repaint without dirtying the scene, so I will make a mod and this problem will disappear with the next CM release. Thank you very much for bringing this up!

    In your original post, there is a difference in scene data, so it must be caused by something else. Can you make a repro project for that problem?
     
  28. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    yup u r Right, there is no difference in my original post project. I am Sorry, I didn't check it before upload. So sorry about that.
    Now I move the CM vcam1 to another position in the SampleScene, and try the same path, it reproduces this issue.

    This image is showing the git diff content.

    截屏2020-04-17 上午9.25.03.png
    I re-upload the sample project, please download and check this issue.

    Thanks for ur patience !!
     

    Attached Files:

  29. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    So yes, the procedural positioning code is doing dynamic transform calculations, and these are subject to tiny precision fluctuations - this is normal. When I run your scene, for example, I see the vcam's rotation fluctuating between 180 and -180. Invisible to the eye, but bitwise-different, so enough to trigger the "scene is dirty" logic.

    The problem you are encountering is that you have enabled the "Save During Play" option of Cinemachine. This option is intended for camera designers to tweak vcam settings during play mode, and to have those changes carried back to the scene when play mode is stopped. Since Cinemachine can't detect which changes are wanted, and which changes are side-effects, it carries everything back - including changes to the transform. Those are the changes that are being saved in your case.

    The solution is to simply disable that option:

    upload_2020-4-17_7-49-23.png

    You only have to disable it once - it is a global setting, and will be remembered. If and when you need this functionality to fine-tune your vcams during game play, you can turn it back on.
     
  30. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    The solution is to simply disable that option:

    View attachment 600295

    You only have to disable it once - it is a global setting, and will be remembered. If and when you need this functionality to fine-tune your vcams during game play, you can turn it back on.[/QUOTE]

    Sorry but I didn't enable 'Save During Play' option all the time. 截屏2020-04-17 下午10.56.58.png
     
  31. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Without that option checked, I was not seeing the changed values in your new project when I exited play mode, or selected/deslected the vcam.

    Save the scene once after exiting play mode. It should be stable after that.
     
  32. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    Oh no, it still happen when play-stop the game or selected/deslected the vcam in my project. Really sucks.(crying)
     
  33. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    Tell me the exact repro steps please, starting with "open the project in Unity x.x."
     
  34. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    There is no special step, just play-stop the game or selected/deslected the vcam can repro. I don't know why it is stable when u Save the scene once after exiting play mode. Do u have other operators? what is ur CM version and Unity version? It is no sense we have different result with the same Project and the same steps. I am confused.
     
  35. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    I am using Unity 2019.3.4f1, and CM 2.6.0-preview.3. Don't forget that CM 2.5.0 will show the little star on the scene, even if the content is unchanged - this has been fixed in 2.6.0-preview.3.
     
  36. TefarMain

    TefarMain

    Joined:
    Mar 24, 2019
    Posts:
    22
    OK, can u try Unity 2019.3.4f1 and CM 2.5.0 to repro, the content is really changed, trust me.
     
  37. kyuskoj

    kyuskoj

    Joined:
    Aug 28, 2013
    Posts:
    56
    Still occurs in 2023.2.15. cinemachine 2.9.7
    Fixed in 3.0.1 :)
     
    Last edited: Mar 26, 2024