Create a UI Magnifier in Unity (URP) Using a Second Camera

A magnifier inside the UI is useful for highlighting 3D models, inspecting objects, or providing accessible zoom functionality. This guide explains how to create a magnifier panel in Unity using a secondary camera and a RenderTexture, fully compatible with the Universal Render Pipeline (URP).

An orange alarm clock, with number twelve magnified
Step 1: Set Up the Magnifier Camera

Create a new camera and name it MagnifierCamera. Adjust the following settings.

Key camera properties:

  • Projection: Perspective or Orthographic, depending on content
  • Background Type: Uninitialised (to ensure transparency in URP)
  • Culling Mask: Use a custom layer (e.g. Magnifier) to isolate magnified objects
  • Post Processing, Shadows, Depth Texture: Disabled to improve performance
  • Output Texture: Assign a RenderTexture (details in the next step)
Unity editor showing camera settings configured to render to a texture named "MagnifierRenderTexture."

Position the camera so it frames the object or content to magnify.

Step 2: Create and Assign a RenderTexture
  1. In the Project window, right-click and select Create > Render Texture
  2. Name it MagnifierRenderTexture
  3. Set the desired resolution (e.g. 512×512 or 1024×1024)
  4. Assign this RenderTexture to the Output Texture field of the magnifier camera
Unity editor showing settings for a 640x360 render texture named "Magnifier Render Texture" with depth, no anti-aliasing, and bilinear filtering.

This texture will be updated automatically by the camera each frame.

Step 3: Display the RenderTexture in the UI
  1. Inside a Canvas, add a RawImage component
  2. Set the Texture property to MagnifierRenderTexture
  3. Resize and position the RawImage wherever the magnifier should appear
Unity editor showing a Raw Image UI component using "MagnifierRenderTexture" as its texture with default UV and colour settings.

This will display the live camera view inside your UI, fully separate from the main scene camera.

Step 4: Fade the Magnifier In and Out

To fade the magnifier UI panel, attach a CanvasGroup component and use a coroutine like this:


IEnumerator Fade(CanvasGroup group, float toAlpha, float duration)
{
    float start = group.alpha;
    float time = 0f;
    while (time < duration)
    {
        group.alpha = Mathf.Lerp(start, toAlpha, time / duration);
        time += Time.deltaTime;
        yield return null;
    }
    group.alpha = toAlpha;
    group.blocksRaycasts = group.interactable = toAlpha > 0f;
}

To fade in:


StartCoroutine(Fade(myCanvasGroup, 1f, 0.5f));

To fade out:


StartCoroutine(Fade(myCanvasGroup, 0f, 0.5f));

Optional: Restore Magnifier Only If Previously Active

If an overlay panel (like a reference or guide) temporarily hides the magnifier, preserve the previous user state like this:


bool wasMagnifierActiveBeforeOverlay = magnifierPanel.activeSelf;

Then, after closing the overlay:


if (wasMagnifierActiveBeforeOverlay)
    StartCoroutine(Fade(magnifierCanvasGroup, 1f, 0.5f));

This ensures the magnifier only reappears if the user had it enabled before.

Summary
  • Works cleanly with URP and Canvas UI
  • Uses camera culling for selective magnification
  • Compatible with both 2D and 3D content
  • Avoids overdraw and performance issues common with render layers
  • Ideal for model previews, inspection panels, and training applications

For advanced use cases, the magnifier system can be extended with user-driven zoom, drag-to-pan, or target switching.

We hope this guide has helped you successfully integrate a UI magnifier into your Unity URP project. Curious to see more of how we use Unity in interactive learning and game development? Explore our work here.

Looking to develop custom interactive solutions for your organisation? At Sliced Bread Animation, we specialise in crafting immersive experiences and innovative content. Get in touch to find out how we can bring your ideas to life!

Recent Posts