Render screenshots with transparent backgrounds from Unity3D (free version)

Tomasz Kaye
Feb 12, 2015 · 2 min read

If you do motion graphics work and you use Unity3D you might find yourself wanting to render out sequences of images from your Unity3D projects to import into compositing applications like Adobe After Effects. I needed to do that.

It’s relatively easy to do if you own Unity3D Pro thanks to support for Render Textures, here’s a script that uses that approach. With a clever workaround you can get transparent background images out of the the free version of Unity3D too.

I first saw the technique described by user Twinfox in this thread. It involves rendering each frame twice, once with a black background and once with a white one, then looking at the differences in pixel colours between the two to derive a final output image with a transparent background.

At the bottom of this post I’ve embedded the script I’ve written that uses this approach. Feel free to use/modify it without restriction.

Here’s how to get it working:

  1. Save the script in your project as: TransparentBackgroundScreenshotRecorder.cs.
  2. In your scene, attach the script to the Game Object that carries the camera whose viewpoint you’d like to use.
  3. In the inspector, set the frameRate value for the attached script. This determines how many screenshots will be captured for each second of ‘game time’.
  4. In the inspector set the framesToCapture to determine how many screenshots will be made.
  5. Choose the desired resolution in Unity’s Game window using the dropdown at the top left. You’ll need to use a resolution that’s less than or equal to your screen’s resolution to get the size of image you specify. I usually use 1920 x 1080 for my video projects.
  6. Turn on the ‘Maximise on Play’ switch in the Game window.
  7. Play your scene from the editor.

The scene will appear to play very slowly, with a white background, meanwhile screenshots are being saved to [PathToYourUnityProject]/Screenshots by default. A number will be appended to the folder name if there’s a naming collision.

The script will exit back to the editor once the desired number of frames have been captured.

Since playback while capturing is very slow and jerky, it isn’t suited to sequences that respond in a time-sensitive way to player input, but works well for recording anything that runs automatically.


    Tomasz Kaye

    Written by

    Anti-political propaganda animations. Market anarchist. Netherlands.

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade