1. Character controller variant (Ultimate Character Controller, First Person Controller, etc).
Third Person Controller 2.2
Cinemachine Integration
Cinemachine 2.5.0
2. Unity version (include which SRP, beta Unity versions aren't supported)
2019.3.9f1
3. Bug description
- I have 2 ViewTypes, each with it's own FreeLookVCam
- I use the "State system" to switch between the two ViewTypes
- I use the OnChangeViewType Event of the camera controller to switch the Vcam using the following code:
- When CameraController:SetViewType() kicks in, it calls m_ViewType.ChangeViewType() before executing the "OnChangeViewType" event
- As a result, Cinemachine.UpdateFreeLookCameraValues:186 m_Brain.ActiveVirtualCamera, still references the old VCam.
- Actually, executing a new "OnWillChangeViewType" event before the m_ViewType.ChangeViewType() call in CameraController:SetViewType() does not work either (because the VCam Brain will only update the ActiveVirtualCamera in the next Frame?)
- Changing Cinemachine:ChangeViewType() to always subscribe to the m_CameraActicatedEvent solves the problem for me. This updates the FreeLookCameraValues twice but that should be fine IMHO:
Is there a better way to switch VCams based on the active ViewType?
Thanks!
Third Person Controller 2.2
Cinemachine Integration
Cinemachine 2.5.0
2. Unity version (include which SRP, beta Unity versions aren't supported)
2019.3.9f1
3. Bug description
- I have 2 ViewTypes, each with it's own FreeLookVCam
- I use the "State system" to switch between the two ViewTypes
- I use the OnChangeViewType Event of the camera controller to switch the Vcam using the following code:
Code:
private void OnChangeViewType(ViewType viewType, bool isActive)
{
var vcams = m_CameraController.Character.GetComponentsInChildren<CinemachineVirtualCameraBase>();
foreach (var vcam in vcams)
{
var viewTypeName = (viewType.FirstPersonPerspective ? "FirstPerson" : "ThirdPerson") + viewType.GetType().Name;
vcam.Priority = vcam.gameObject.name == viewTypeName ? 11 : 10;
}
}
- When CameraController:SetViewType() kicks in, it calls m_ViewType.ChangeViewType() before executing the "OnChangeViewType" event
- As a result, Cinemachine.UpdateFreeLookCameraValues:186 m_Brain.ActiveVirtualCamera, still references the old VCam.
- Actually, executing a new "OnWillChangeViewType" event before the m_ViewType.ChangeViewType() call in CameraController:SetViewType() does not work either (because the VCam Brain will only update the ActiveVirtualCamera in the next Frame?)
- Changing Cinemachine:ChangeViewType() to always subscribe to the m_CameraActicatedEvent solves the problem for me. This updates the FreeLookCameraValues twice but that should be fine IMHO:
Code:
public override void ChangeViewType(bool activate, float pitch, float yaw, Quaternion characterRotation)
{
m_Brain.enabled = activate;
if (activate) {
m_Pitch = pitch;
if (m_Camera.fieldOfView != m_FieldOfView) {
m_FieldOfViewChangeTime = Time.time + m_FieldOfViewDamping / m_CharacterLocomotion.TimeScale;
}
// A virtual camera will not exist when Cinemachine first starts.
if (m_Brain.ActiveVirtualCamera == null) {
m_Brain.m_CameraActivatedEvent.AddListener(ActivatedVirtualCamera);
} else {
+ m_Brain.m_CameraActivatedEvent.AddListener(ActivatedVirtualCamera);
UpdateFreeLookCameraValues();
}
} else {
m_FreeLook = null;
}
}
Is there a better way to switch VCams based on the active ViewType?
Thanks!