How to create screenshot in New Editor Window (PIE) with custom depth stencil values?

I would like to create screenshots of the camera perspective automatically after modifying custom depth stencil values for specific meshes in my project.
It appears to work fine when using Play Mode “Selected Viewport”, but as soon as I switch to “New Editor Window (PIE)”, the screenshots are completely black, meaning that custom depth stencil values are ignored.
I can reproduce this behavior in a new project:

  1. Enable Custom Depth Stencil Pass in Project Settings:
    01_project_settings
  2. Create a post processing material with custom stencil:
  3. Create mappings to…:
  • …enable custom depth rendering & assign the post processing material to the camera as weighted blendable
  • …set the custom depth stencil value for one object to be rendered
  • …take a screenshot of the result

You can see the results below:

  • Run in Selected Viewport:
  1. Initial Viewport display
  2. Viewport display after applying the post processing material to the camera
  3. Viewport display after setting custom stencil value
  4. Result of screenshot triggered within UE4
  • Run in New Editor Window (PIE):
  1. Initial Editor Window display
  2. Editor Window display after applying the post processing material to the camera
  3. Editor Window display after setting custom stencil value
  4. Result of screenshot triggered within UE4

As you can see, the results of steps 1-3 look very similar, but the screenshot functionality seems to produce different results depending on the Play Mode. In New Editor Window (PIE), it does not reflect the rendered mesh with custom stencil value.
What I also tested: Prepare steps 1-3 by setting the respective property values statically (no changes at run-time). In that case, both Play Modes succeed to create a screenshot of the rendered scene.
I am using UE 4.27.1.

Do you have any idea why the TakeHighResScreenshot function struggles with run-time changes of custom depth rendering in New Editor Window (PIE) Play Mode?
I need to use that Play Mode because I failed to set the resolution dynamically for the Selected Viewport Play Mode which is also a requirement for my project.