docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class CinemachineConfiner2D

    An add-on module for Cinemachine Virtual Camera that post-processes the final position of the virtual camera. It will confine the camera's position such that the screen edges stay within a shape defined by a 2D polygon. This will work for orthographic or perspective cameras, provided that the camera's forward vector remains parallel to the bounding shape's normal, i.e. that the camera is looking straight at the polygon, and not obliquely at it.

    When confining the camera, the camera's view size at the polygon plane is considered, and also its aspect ratio. Based on this information and the input polygon, a second (smaller) polygon is computed to which the camera's transform is constrained. Computation of this secondary polygon is nontrivial and expensive, so it should be done only when absolutely necessary.

    The cached secondary polygon needs to be recomputed in the following circumstances:

    • when the input polygon's points change
    • when the input polygon is non-uniformly scaled
    • when the input polygon is rotated
    For efficiency reasons, Cinemachine will not automatically regenerate the inner polygon in these cases, and it is the responsibility of the client to call the InvalidateCache() method to trigger the recalculation. An inspector button is also provided for this purpose.

    If the input polygon scales uniformly or translates, the cache remains valid. If the polygon rotates, then the cache degrades in quality (more or less depending on the aspect ratio - it's better if the ratio is close to 1:1) but can still be used. Regenerating it will eliminate the imperfections.

    The cached secondary polygon is not a single polygon, but rather a family of polygons from which a member is chosen depending on the current size of the camera view. The number of polygons in this family will depend on the complexity of the input polygon, and the maximum expected camera view size. The MaxOrthoSize property is provided to give a hint to the algorithm to stop generating polygons for camera view sizes larger than the one specified. This can represent a substantial cost saving when regenerating the cache, so it is a good idea to set it carefully. Leaving it at 0 will cause the maximum number of polygons to be generated.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    CinemachineExtension
    CinemachineConfiner2D
    Inherited Members
    CinemachineExtension.Epsilon
    CinemachineExtension.VirtualCamera
    CinemachineExtension.Awake()
    CinemachineExtension.OnEnable()
    CinemachineExtension.OnDestroy()
    CinemachineExtension.ConnectToVcam(bool)
    CinemachineExtension.PrePipelineMutateCameraStateCallback(CinemachineVirtualCameraBase, ref CameraState, float)
    CinemachineExtension.InvokePostPipelineStageCallback(CinemachineVirtualCameraBase, CinemachineCore.Stage, ref CameraState, float)
    CinemachineExtension.OnTargetObjectWarped(Transform, Vector3)
    CinemachineExtension.ForceCameraPosition(Vector3, Quaternion)
    CinemachineExtension.OnTransitionFromCamera(ICinemachineCamera, Vector3, float)
    CinemachineExtension.GetMaxDampTime()
    CinemachineExtension.RequiresUserInput
    CinemachineExtension.GetExtraState<T>(ICinemachineCamera)
    CinemachineExtension.GetAllExtraStates<T>()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.destroyCancellationToken
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.GetComponentIndex()
    Component.CompareTag(string)
    Component.SendMessageUpwards(string, object, SendMessageOptions)
    Component.SendMessageUpwards(string, object)
    Component.SendMessageUpwards(string)
    Component.SendMessageUpwards(string, SendMessageOptions)
    Component.SendMessage(string, object)
    Component.SendMessage(string)
    Component.SendMessage(string, object, SendMessageOptions)
    Component.SendMessage(string, SendMessageOptions)
    Component.BroadcastMessage(string, object, SendMessageOptions)
    Component.BroadcastMessage(string, object)
    Component.BroadcastMessage(string)
    Component.BroadcastMessage(string, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    Object.InstantiateAsync<T>(T)
    Object.InstantiateAsync<T>(T, Transform)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, InstantiateParameters)
    Object.InstantiateAsync<T>(T, int, InstantiateParameters)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion, InstantiateParameters)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, InstantiateParameters)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate<T>(T, InstantiateParameters)
    Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Cinemachine
    Assembly: Cinemachine.dll
    Syntax
    [AddComponentMenu("")]
    [ExecuteAlways]
    [DisallowMultipleComponent]
    [HelpURL("https://docs.unity3d.com/Packages/com.unity.cinemachine@2.9/manual/CinemachineConfiner2D.html")]
    public class CinemachineConfiner2D : CinemachineExtension

    Fields

    m_BoundingShape2D

    The 2D shape within which the camera is to be contained.

    Declaration
    [Tooltip("The 2D shape within which the camera is to be contained.  Can be a 2D polygon or 2D composite collider.")]
    public Collider2D m_BoundingShape2D
    Field Value
    Type Description
    Collider2D

    m_Damping

    Damping applied automatically around corners to avoid jumps.

    Declaration
    [Tooltip("Damping applied around corners to avoid jumps.  Higher numbers are more gradual.")]
    [Range(0, 5)]
    public float m_Damping
    Field Value
    Type Description
    float

    m_MaxWindowSize

    To optimize computation and memory costs, set this to the largest view size that the camera is expected to have. The confiner will not compute a polygon cache for frustum sizes larger than this. This refers to the size in world units of the frustum at the confiner plane (for orthographic cameras, this is just the orthographic size). If set to 0, then this parameter is ignored and a polygon cache will be calculated for all potential window sizes.

    Declaration
    [Tooltip("To optimize computation and memory costs, set this to the largest view size that the camera is expected to have.  The confiner will not compute a polygon cache for frustum sizes larger than this.  This refers to the size in world units of the frustum at the confiner plane (for orthographic cameras, this is just the orthographic size).  If set to 0, then this parameter is ignored and a polygon cache will be calculated for all potential window sizes.")]
    public float m_MaxWindowSize
    Field Value
    Type Description
    float

    m_Padding

    For large window sizes, the confiner will potentially generate polygons with zero area.
    The padding may be used to add a small amount of area to these polygons, to prevent them from being a series of disconnected dots.

    Declaration
    [Tooltip("For large window sizes, the confiner will potentially generate polygons with zero area.  The padding may be used to add a small amount of area to these polygons, to prevent them from being a series of disconnected dots.")]
    [Range(0, 100)]
    public float m_Padding
    Field Value
    Type Description
    float

    Methods

    InvalidateCache()

    Invalidates cache and consequently trigger a rebake at next iteration.

    Declaration
    public void InvalidateCache()

    PostPipelineStageCallback(CinemachineVirtualCameraBase, Stage, ref CameraState, float)

    Callback to do the camera confining

    Declaration
    protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    Parameters
    Type Name Description
    CinemachineVirtualCameraBase vcam

    The virtual camera being processed

    CinemachineCore.Stage stage

    The current pipeline stage

    CameraState state

    The current virtual camera state

    float deltaTime

    The current applicable deltaTime

    Overrides
    CinemachineExtension.PostPipelineStageCallback(CinemachineVirtualCameraBase, CinemachineCore.Stage, ref CameraState, float)

    ValidateCache(float)

    Validates cache

    Declaration
    public bool ValidateCache(float cameraAspectRatio)
    Parameters
    Type Name Description
    float cameraAspectRatio

    Aspect ratio of camera.

    Returns
    Type Description
    bool

    Returns true if the cache could be validated. False, otherwise.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)