Search Unity

Where is the "AddPostPipelineStageHook"

Discussion in 'Cinemachine' started by okokok126, Nov 28, 2018.

  1. okokok126

    okokok126

    Joined:
    Feb 27, 2013
    Posts:
    3
    Hello,

    In my project I use AddPostPipelineStageHook to offset camera final position.
    When I upgraded Cinemachine to 2.2.7, I can't find the "AddPostPipelineStageHook" in CinemachineVirtualCameraBase.

    Where is the "AddPostPipelineStageHook" function, or is there any API can offset camera final position?

    thanks,
    Wayne
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    What version of CM were you using before upgrading?
     
  3. okokok126

    okokok126

    Joined:
    Feb 27, 2013
    Posts:
    3
    I was using CM v2.1 before upgrading.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    So there is a new thing called CinemachineExtension that you need to look at. Create one, drop it in your project, and it will appear in the "Extensions" dropdown at the bottom of the vcam inspector.

    Here is a sample one that does camera offset:
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. /// <summary>
    5. /// An add-on module for Cinemachine Virtual Camera that adds a final offset to the camera
    6. /// </summary>
    7. [AddComponentMenu("")] // Hide in menu
    8. public class CinemachineVcamOffset : CinemachineExtension
    9. {
    10.     [Tooltip("Offset the camera's position by this much (camera space)")]
    11.     public Vector3 m_Offset = Vector3.zero;
    12.  
    13.     protected override void PostPipelineStageCallback(
    14.         CinemachineVirtualCameraBase vcam,
    15.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    16.     {
    17.         // Apply after the camera has been aimed
    18.         if (stage == CinemachineCore.Stage.Aim)
    19.         {
    20.             Vector3 offset = state.FinalOrientation * m_Offset;
    21.             state.ReferenceLookAt += offset;
    22.             state.PositionCorrection += offset;
    23.         }
    24.     }
    25. }
    26.  
     
  5. okokok126

    okokok126

    Joined:
    Feb 27, 2013
    Posts:
    3
    Awesome, it works perfectly.
    Thank you so much for the quick reply.
     
    Gregoryl likes this.