How to mask objects using a directional or spot light?

I was curious, how would you go about using a light to mask an object? I came across this video (UE4 Object Mask l Unreal Engine 4.26 (Tutorial) - YouTube) and I was thinking: Would it be possible to use the rays of a light to mask out an object or am I overcomplicating things and is there a simpler way of doing something similar?

My usage case would be a light starts shining on a wall and where ever the light hits the wall becomes see-through and you can see things on the other side.

Any thoughts?