Render Invisible Object Through Another Object

Hello! So recently I have been working on a prototype for a searchlight game I am trying to make. The idea is that the rectangle can only be seen when overlapping the searchlight. Right now I’ve just made the rectangle able to render through walls using this tutorial, and it works when I run the searchlight over it:


However, the rectangle and background are both black. If this is not the case, the rectangle will be seen when not under the searchlight. So I want to make it where the rectangle is invisible except when under the searchlight. I tried just adding an invisible (Opacity = 0) material to the rectangle, and hoping it would still render through the searchlight, but this is not the case. When the rectangle is invisible, it remains invisible even behind the searchlight. I’d like to know how I can do this correctly.

edit: For more detail, this is whats currently happening:


And this is what I want to happen:

Nevermind, I found that if you disable Render in Depth Pass and Render in Main Pass on the mesh, it will be hidden, but the custom depth will still work. Using this solution, I simply put the plane in front of the background and behind the searchlight, which works well.