Skip to main content

Render textures (cameras on screens)

A render texture is a picture that a camera draws into instead of drawing to the player's screen. A material can then show that picture on any surface. This is how you make a security-camera monitor, a TV that shows another room, a rear-view mirror, a portal or a minimap.

It works the way Unity does it, in three parts:

  1. A render texture is a file you make in Files → + New → Render texture.
  2. A camera has a Target texture setting. Pick the render texture there and that camera draws into it.
  3. A material has a Render texture setting. Pick the same file and the surface shows what the camera sees.

Example: a security monitor​

  1. Files → + New → Render texture, name it Monitor.
  2. Add → Camera, name it Security cam. Put it up in a corner of the room and turn it to look at the floor. In its settings, set Target texture to Monitor. The camera no longer shows the game; it only feeds the monitor.
  3. Add a flat box for the screen (about 4 wide, 3 tall, thin), in the office. In its Material, set the style to Unlit and Render texture to Monitor.
  4. Press Play. The screen shows what the security camera sees, live.

Use the Unlit style (MeshBasicMaterial) for a screen. A lit style would shade the picture like a wall; an unlit one shows the picture as it is, like a real screen.

The render texture file​

Tap it in Files for Size and Update:

SettingWhat it does
SizeWidth and height in pixels: 128, 256, 512 or 1024. Bigger is sharper and costs more. A monitor in a corner of the screen needs 256 or 512.
Update: AlwaysDrawn on every frame, like Unity.
Update: Only when seenDrawn only while a surface showing it is in view of the game's camera. A monitor in another room costs nothing until you walk in.
EveryDraws on every 2nd, 3rd, 4th, 6th or 10th frame instead of every one. A security feed that updates 10 times a second looks right and costs much less.

On a Sprite​

A Sprite object has a Render texture row too. It shows the camera's picture instead of its drawing, live, in the game: a flat screen that can face the camera (Billboard), be tinted, faded and sorted like any sprite. Its size comes from the render texture's size and Pixels per unit. It shows in the scene view too.

On the HUD (a minimap)​

Select a UI Image and pick a Render texture in its Image section. The element then shows the camera's picture live, in the corner of the screen or wherever you place it. Use Preserve aspect to keep the picture's proportions inside the rect.

Every picture is copied from the graphics card into the HUD, so keep the render texture small (256 or less is plenty for a minimap) and use Every to draw it less often.

Leave things out of a camera​

A camera with a Target texture has a Draw switch for every layer. Switch a layer off and the camera's picture shows nothing from it: put the clouds on a Clouds layer and the minimap shows no clouds. The game's own camera has the same switches, so a Minimap layer of markers can show in the minimap and nowhere else.

From events and scripts​

  • Event block Render texture: Pause freezes the picture (the last one stays), Resume starts it again, Draw once draws a single new picture even while paused.
  • Script: game.renderTexture('Monitor').paused = true, .paused = false, .refresh(); also name, width, height. It throws when the project has no render texture of that name.

Switch what a surface shows​

A TV that flips between security cameras: make a render texture per camera, then change which one the screen shows while the game runs.

  • Event block Show render texture (Graphics): pick the object and the render texture. Leave the texture empty to put the object's own picture back.
  • Script: tv.setRenderTexture('Cam B'), and tv.setRenderTexture(null) for its own picture. It returns false when the object has nothing to show it on, and throws for a name the project doesn't have.

It works on a mesh with a built-in style (every surface of the object), a Sprite, and a UI Image or Panel. Only that object changes, not the other objects sharing its material.

A pause or a switch is for the running game only; it is not saved.

Good to know​

  • Each camera feeding a render texture draws the whole scene a second time. On phones this is the most expensive thing in this list. Keep the size small, use Only when seen and Every, and use as few as you need.
  • A camera with a Target texture is never the game's camera, even with Main camera on. The game's own view is chosen from the other cameras.
  • The surface that shows a render texture is hidden from the camera that feeds it, so a camera never sees its own screen.
  • The picture has the shape of the render texture, not of the screen, so use a camera field of view that suits it (a square texture on a wide screen is stretched).
  • Several surfaces can show the same render texture, and one render texture can be fed by only one camera at a time (if two cameras are set to the same one, the later one in the object list wins).
  • Screen effects (glow, depth of field, vignette) are not applied inside a render texture, only to the game's own picture.
  • Shows in the scene view and in Play. In the scene view each camera draws again whenever the view redraws, and the editor's own guides (grid, handles, camera icons) are left out of the picture. The HUD image shows in Play only.
  • Deleting the render texture file turns its cameras back into ordinary cameras and clears the setting on the materials that used it.
  • Materials with a custom shader can't show one, as with videos. Use a built-in style.