I’ve been doing some composite work in UE4, the final step of which is to use the High Resolution Screenshot tool to capture an image using the custom depth as a mask.
What this is supposed to do is capture only objects that are rendering with custom depth and mask out everything else. The result should be a nice rendering of only the custom depth objects and a transparent background, ready for compositing.
In practice, I was finding that I couldn’t even see my custom depth objects, as if there were a far clipping plane obscuring them.

The Setup
For each object that should exist in your mask, you have to select it and check the following option. You may have to do this in bulk depending on your scene.

Next you use the screenshot tool and enable Use Custom Depth as Mask.

If you only see a purely green screen at this point, then read on.
The Solution
After a bit of sleuthing, I found a mask material provided by the engine, it calls a single material function:
Engine/EngineMaterials/HighResolutionScreenshotMaskFunction
If you open this function, you will see the nodes below.

The constant that is circled is the maximum scene depth that the material will render. The default is 10,000, so anything beyond this distance will be lost. Increase this value to the maximum distance that your objects will be from the camera.
How do you make changes to this engine material? I can’t seem to access it from the editor.
You may need to change the “View Options” (the eye icon on the bottom right of the content browser) to show engine content. Then select the “Engine” category in the content browser and search for it there.
This sounds like just exactly what I need, but Unreal tells me I do not have “sufficient permission to save content” – any idea how to get around this?
This is a little problematic since the content being modified is engine content. In my case I had compiled my own engine and so could modify the content. If you are running the binary engine, you may need to perhaps run the engine as administrator and/or make sure that the file in question [YourEngineFolder]\Engine\Content\EngineMaterials\HighResolutionScreenshotMaskFunction.uasset is not set to read only. Let me know if either of these work.
Thanks for the suggestions! Just checked the file and it’s not set to read-only, so I suspect I need to run the engine as an admin. Running as an admin would be the next thing to try but because it’s a work machine that can complicate things (my admin login has its own directory structure). Until then I can get by tweaking it temporarily just to get the alpha mask.