Render screenshots with transparent backgrounds from Unity3D (free version)

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.

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.

TransparentBackgrounScreenShotRecorder.cs

Anti-political propaganda animations. Market anarchist. Netherlands.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store