Help with depth texture

Godot Version

4.4

Question

I’m new to Godot shaders so I’m probably just making a silly mistake here but:

I’m trying to hide an object if it’s behind another invisible object.
I have a shader on the occluding object that sets ALPHA to 0 and DEPTH to 1.
I then converted a standard material to a shader and am trying to check hint_depth_texture to see if it’s greater than DEPTH, and then setting ALPHA to 0 if it is.

But for some reason if I sample the depth texture at all, even if I do nothing with it, the mesh is displayed overtop of everything and the back faces are drawn overtop the front ones.

Can anyone help me get this working?
Or maybe there’s a better way to achieve this?

Thanks