Search Unity

Question Dynamically changing recentering / wait time having no effect and not changing in editor

Discussion in 'Cinemachine' started by hunternance93, Nov 7, 2022.

  1. hunternance93

    hunternance93

    Joined:
    May 25, 2016
    Posts:
    7
    Hello,

    I am trying to do a rather specific set of things with a Cinemachine camera. Basically, I want the camera to be a POV, but to slowly re-center onto a specific object, and over a period of time I want the wait time and recenter time to decrease, so that the player is more and more forced to look at an object. The code I'll post looks a little weird because I tried a lot of things (like the disable/enable game object thing was a last ditch effort, lol), but all of the debug logs give me values of exactly what I would expect / the "correct" numbers.. but when I look in editor on ToiletCamera's Aim values they are not updated. If I update them in editor, they behave as I would expect. It seems like the POV's values are appropriately changing, but the change is having no effect. The most relevant code is that in the while (timer < 30) loop, the rest is just other stuff related to the scene that is hard to explain.

    Code (CSharp):
    1.     private IEnumerator TransitionToToiletCam()
    2.     {
    3.         GameManager.instance.FadeOut();
    4.         //GameManager.instance.SwitchInput(GameManager.instance.controls.None.Get());
    5.         yield return new WaitForSeconds(1);
    6.         //Set camera
    7.         toiletCam.Priority = 999;
    8.         CinemachinePOV POV = toiletCam.GetCinemachineComponent<CinemachinePOV>();
    9.         Debug.Log("Values before: " + POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_HorizontalAxis.m_Recentering.m_WaitTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_WaitTime);
    10.         POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime = 0;
    11.         POV.m_HorizontalAxis.m_Recentering.m_WaitTime = 0;
    12.         POV.m_VerticalAxis.m_Recentering.m_RecenteringTime = 0;
    13.         POV.m_VerticalAxis.m_Recentering.m_WaitTime = 0;
    14.         Debug.Log("Values after: " + POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_HorizontalAxis.m_Recentering.m_WaitTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_WaitTime);
    15.         toiletCam.gameObject.SetActive(false);
    16.         toiletCam.gameObject.SetActive(true);
    17.         yield return null;
    18.         Debug.Log("Values after waiting a frame: " + POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_HorizontalAxis.m_Recentering.m_WaitTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_WaitTime);
    19.         POV.m_HorizontalRecentering.m_enabled = false;
    20.         POV.m_VerticalRecentering.m_enabled = false;
    21.         POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime = 10;
    22.         POV.m_HorizontalAxis.m_Recentering.m_WaitTime = 3;
    23.         POV.m_VerticalAxis.m_Recentering.m_RecenteringTime = 10;
    24.         POV.m_VerticalAxis.m_Recentering.m_WaitTime = 3;
    25.         toiletCam.LookAt = portrait.transform;
    26.         toiletCam.gameObject.SetActive(false);
    27.         toiletCam.gameObject.SetActive(true);
    28.         Debug.Log("Values after set back: " + POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_HorizontalAxis.m_Recentering.m_WaitTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_WaitTime);
    29.         yield return new WaitForSeconds(1);
    30.         GameManager.instance.FadeIn();
    31.         inspectWindow.SetActive(true);
    32.         while (!HasWindowBeenInspected) yield return null;
    33.         yield return new WaitForSeconds(5);
    34.         POV.m_HorizontalRecentering.m_enabled = true;
    35.         POV.m_VerticalRecentering.m_enabled = true;
    36.         float timer = 0;
    37.         while (timer < 30)
    38.         {
    39.             POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime = Mathf.Lerp(startRecenter, finishRecenter, timer / 30);
    40.             POV.m_VerticalAxis.m_Recentering.m_RecenteringTime = Mathf.Lerp(startRecenter, finishRecenter, timer / 30);
    41.             POV.m_HorizontalAxis.m_Recentering.m_WaitTime = Mathf.Lerp(startWait, finishWait, timer / 30);
    42.             POV.m_VerticalAxis.m_Recentering.m_WaitTime = Mathf.Lerp(startWait, finishWait, timer / 30);
    43.             timer += Time.deltaTime;
    44.             Debug.Log("Values each loop: " + POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_HorizontalAxis.m_Recentering.m_WaitTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_RecenteringTime + "\n" + POV.m_VerticalAxis.m_Recentering.m_WaitTime);
    45.             CinemachinePOV tempPOV = toiletCam.GetCinemachineComponent<CinemachinePOV>();
    46.             Debug.Log("Values each loop TEMP: " + tempPOV.m_HorizontalAxis.m_Recentering.m_RecenteringTime + "\n" + tempPOV.m_HorizontalAxis.m_Recentering.m_WaitTime + "\n" + tempPOV.m_VerticalAxis.m_Recentering.m_RecenteringTime + "\n" + tempPOV.m_VerticalAxis.m_Recentering.m_WaitTime);
    47.             toiletCam.gameObject.SetActive(false);
    48.             toiletCam.gameObject.SetActive(true);
    49.             yield return null;
    50.         }
    51.     }
    And here is the camera set up:


    Anyone have any ideas?

    Thanks for taking a look.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The only thing I can think of is that you have some other thing that's pushing axis values into the POV. I presume that you have an InputProvider behaviour attached? If it detects any user input, it will cancel any recentering currently in progress.

    If you want to completely take over the POV's axes, you can do that. Disable the InputProvider, and modify the axis values at will. You can just implement your own recentering logic, if you like.
     
    Last edited: Nov 7, 2022
  3. hunternance93

    hunternance93

    Joined:
    May 25, 2016
    Posts:
    7
    It isn't that the recentering is being cancelled--it is recentering, it just is not changing the recentering time/wait time values. In other words, it doesn't "speed up". It is especially strange because:

    Code (CSharp):
    1. POV.m_HorizontalRecentering.m_enabled = false;
    2.         POV.m_VerticalRecentering.m_enabled = false;
    the lines modifying the recentering enabled values DO work, and they also change the toggle in editor, whereas the recenteringTime and waitTime values in editor do not change, but if I print out POV.m_HorizontalAxis.m_Recentering.m_RecenteringTime (etc.) then it is the correct values... meaning that it is being changed but it just isn't taking effect for some reason.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    ah! I see the problem. You're changing the recentering time on the wrong thing. The axes come with their own recentering settings, e.g. POV.m_VerticalAxis.m_Recentering, but (confusingly) the POV behaviour doesn't use them. Instead, it uses POV.m_VerticalRecentering and POV.m_HorizontalRecentering. Set the times in there instead.
     
    hunternance93 likes this.
  5. hunternance93

    hunternance93

    Joined:
    May 25, 2016
    Posts:
    7
    That did it! Thanks!!
     
    Gregoryl likes this.