Offset when masking UMG material with Custom Depth/Stencil?

Hello. I would prefer if UI elements didn’t obscure certain actors within a scene, so I’m currently trying to mask out the UMG when widgets overlap specified objects during play.

I’ve programmed UI materials that utilize SceneTexture nodes to create transparencies based off SceneDepth and CustomDepth/Stencil settings, but I’m running into a problem where the resulting mask is not showing up exactly over the intended objects.

In a larger window, there is a minor offset around the masked objects, and this offset is much more pronounced when testing in a smaller window.

(mask slightly offset on pink UMG widget during play within a larger window)

(mask heavily offset on pink UMG widget during play within a smaller window)

Is there some UMG, resolution/scaling, viewport/camera, etc. setting I’ve missed somewhere that’s causing this discrepancy between the Custom Depth/Stencil buffers and how the UI is rendered within different window sizes?

Any advice on hiding UMG widgets over specific objects would also be appreciated if this is a completely wrong approach. I am new to UE4 and still learning my way around the software. Thank you!

This seems to be an editor/viewport issue that goes away when the project is cooked and packaged.

Hey, not really a solution here, but would you mind elaborating on how you got the stencil pass to work in UI ? Whenever I set my material domain to user interface the stencil always returns full white.

This feature is completely broken in UE5, even packaged does not work.
It is still in almost the same state in 5.1.
Is it not recognized as a defect?

I developed a plugin named “SceneTextureForUMG” to solve the problem completely.