Unity Cinemachine Confiner Not Updating After Runtime Bounds Change - Cache Invalidations and Collider2D Refresh Fix

Your level bounds changed, but the virtual camera still behaves like the old polygon or box is in force. The camera may clamp early, leave dead space at the edges, or refuse to reach new areas until you toggle the confiner in the Inspector. That pattern usually means Cinemachine cached geometry instead of a broken follow target.

This article explains why Cinemachine defers expensive recomputation, how to invalidate caches after real bounds changes, and how to handle 2D composite colliders and lens size changes that also require a refresh.

Who is affected and fastest fix

You are likely affected if:

  • a PolygonCollider2D or TilemapCollider2D boundary changes at runtime and the camera still stops at the old edge
  • you scale a parent of the bounding shape non-uniformly and confinement stops matching the visible collider
  • you use CompositeCollider2D and rebake geometry after procedural tiles change
  • your orthographic size or field of view changes a lot at runtime and the confiner feels wrong until you touch the component

Fastest safe fix (Cinemachine 3.x): after you finish mutating the bounding collider or volume, call InvalidateBoundingShapeCache() on your CinemachineConfiner2D (or the appropriate confiner component for your setup). If you only changed lens size, call InvalidateLensCache() on the same component.

Cinemachine 2.x: on CinemachineConfiner2D, call InvalidateCache(). On the 3D CinemachineConfiner, when the 3D volume mesh or collider points change, call InvalidatePathCache() (see Unity manual for your package version).

Official reference: Cinemachine Confiner 2D (package 3.x) documents when the inner polygon cache must be recomputed and why it is not automatic.

Why this happens

Cinemachine confines the camera by precomputing a secondary inner region from your bounding shape and the current view size. That computation is costly for complex polygons, so the package caches results.

Caches must be recomputed when, among other cases:

  • polygon points move, are added, or are removed
  • the shape is non-uniformly scaled
  • the shape is rotated (quality can degrade until you refresh)
  • CompositeCollider2D geometry is regenerated
  • the camera lens orthographic size or field of view changes enough that the cached family of polygons is no longer valid (lens cache)

Uniform translation of the same collider often does not require a bounding-shape cache rebuild, which is why simple room shifts look fine while reshaping the room does not.

Fix 1 - Invalidate after you change 2D collider geometry

Call invalidation once after the frame where collider data is finalized (after tilemap updates, point edits, or composite bake).

Cinemachine 3.x (Unity 6 / com.unity.cinemachine 3.x)

using Unity.Cinemachine;

public sealed class ConfinerBoundsChangedNotifier : MonoBehaviour
{
    public CinemachineConfiner2D confiner;

    public void NotifyBoundsChanged()
    {
        if (confiner != null)
        {
            confiner.InvalidateBoundingShapeCache();
        }
    }
}

If you changed orthographic size or FOV on the Cinemachine camera and the confiner feels stale, also invalidate lens-dependent data:

confiner.InvalidateLensCache();

Cinemachine 2.x (com.unity.cinemachine 2.x)

using Cinemachine;

public sealed class ConfinerBoundsChangedNotifier2 : MonoBehaviour
{
    public CinemachineConfiner2D confiner;

    public void NotifyBoundsChanged()
    {
        if (confiner != null)
        {
            confiner.InvalidateCache();
        }
    }
}

Namespace and type names differ by major version. If your script fails to compile, check Window > Package Manager for the installed Cinemachine major version and match the API from that version’s scripting reference.

Fix 2 - CompositeCollider2D and Tilemaps

When tiles change, the CompositeCollider2D mesh can update a frame later than your gameplay code expects.

Checklist:

  1. finish tilemap edits (Tilemap.SetTiles, flood fill, or your builder)
  2. if you use composite geometry, ensure the composite collider has up-to-date geometry (call CompositeCollider2D.GenerateGeometry() when your workflow requires an explicit regen)
  3. then call InvalidateBoundingShapeCache() (CM3) or InvalidateCache() (CM2) on the confiner

If you invalidate too early, you may still cache the old composite outline. Add a late pass (next frame or Physics2D.SyncTransforms() after writes, when appropriate for your project) if you still see one-frame stale clamps.

Fix 3 - 3D confiners and volumes

For CinemachineConfiner with a 3D bounding volume, changing mesh or collider topology requires the path cache to refresh. Use InvalidatePathCache() on the 2.x API when the documentation for your package version lists it for your confiner type.

Keep the bounding shape reference pointing at the collider or volume you actually mutate. Swapping colliders without updating the confiner field produces the same “stuck bounds” symptom without any cache bug.

Fix 4 - Parent scale and transform hierarchy

Non-uniform scale on parents of the bounding polygon is a common trigger. After you adjust scale, invalidate the confiner cache even if the collider component itself did not log a change.

If invalidation still fails to pick up hierarchy changes, temporarily disable and re-enable the CinemachineConfiner2D component after the transform stack settles. Treat this as a last resort because it can interrupt blending; prefer explicit invalidation API calls first.

Verification checklist

  1. Move the player or free camera to a point that should be legal under the new bounds but was illegal under the old bounds. Confirm the camera reaches it without phantom clamping.
  2. Walk the full perimeter once. Hit corners where old polygons used to pinch the camera.
  3. Change orthographic size through your real gameplay path (zoom), then repeat step 1. If zoom breaks confinement until invalidation, keep InvalidateLensCache() paired with your zoom pipeline.
  4. Capture one before/after log line that records when invalidation ran relative to collider edits (helps prevent double-invalidates in the same frame).

Alternative mitigations

  • Two confiners, blend cameras: for large procedural worlds, Unity’s docs note that switching between cameras with different static shapes and blending can be cheaper than constantly mutating one confiner and invalidating every frame.
  • Simpler bounding shape during edits: drive gameplay with detailed tiles, but confine the camera with a simpler proxy collider you control explicitly, invalidating once when the proxy updates.

Prevention tips

  • centralize level bounds changes in one module that always ends with NotifyBoundsChanged()
  • avoid per-frame invalidation unless bounds truly change every frame; cache rebuilds are not free
  • document your Cinemachine major version in the repo so scripts use the correct namespace (Unity.Cinemachine vs Cinemachine)

FAQ

Why does the Inspector “Invalidate Bounding Shape Cache” button fix it instantly?

The button calls the same invalidation path as the API. Your runtime code path simply did not call it after the collider changed.

Do I need invalidation for uniform scale or translation?

Often no for bounding shape cache if the change is uniform scale or pure translation of the same polygon. When in doubt after procedural edits, invalidate once. Rotations and non-uniform scale are the usual triggers.

Can I call InvalidateBoundingShapeCache every frame?

You can, but it defeats the cache and can hurt performance on complex polygons. Prefer event-driven calls when bounds change.

Related problems and links

Bookmark this page if you ship procedural maps or runtime arena resizing so the fix stays one search away during your next playtest build.