Help needed for rendering transparency with object obstruing the view

Hi,

So i want to render a scene in which ghosts are moving around, and they are composed of mulitple meshes. I want to make them transparent and add effects to them in post processing, so i thought i would render them separted from the background and add them up later in post with transparency. Is there a way that i can render a scene without certain object, but basically transforming them into masks ? I want that if my ghost go behind an object they wouldn’t be seen, but if i delete the object to render just the ghost, it doens’t work.

How can i go about it ?

I think the HoldOut option is what you are after.
Here the sphere is your ghost and the cube the object you want to use as a mask.
You have to put the cube in its own collection and activate the hold out icon, to see the Holdout icon you have to click the “funel” icon at the top of the outliner and select it.

that’s perfect ! thanks a lot