Texture target of scene capture doesn't get updated custom depth

I’m using a scene capture component to render to texture, with the addition of a Post Process material using custom depth stencil to highlight objects. Scene capture has capture every frame and capture on movement active. In 4.16 there was a small bug that asked me to deactivate and activate (by editor UI or C++) custom depth on each object where the stencil value changed, otherwise the change was not seen in the texture.

mesh->SetRenderCustomDepth(false);
mesh->SetRenderCustomDepth(true);

With the upgrade to engine version 4.17, this trick apparently does not work anymore in C++ (SetRenderCustomDepth changes the flag, but no change in the texture), only from the UI: still no automatic update of the texture but neither a way to do that by code.

If it is a bug, I didn’t find previous topics about it. Otherwise, if someone would kindly point me what’s wrong in this approach.

One small and maybe related glitch is that in the new Primitive Render drop down list inside the scene capture, there are two “Render Scene Primitives” voices, with the second of them not being selectable by UI, while apparently it is by C++ code.