Stencil buffer overlays

Hi all,

Could somebody help me. I try to understand stencil buffer. I have put in shader something like this:

For moving object:
Properties
{
_Ref(“Layer”, int) = 0
_Comp(“ComparitionEnum”, Int) = 6
}
Stencil
{
Ref [_Ref]
Comp [_Comp] //notequal
Pass Keep
}

For walls:
Properties
{
_Ref(“Layer”, int) = 0
}
Stencil
{
Ref [_Ref]
Comp Always
Pass replace
}

Unfortunately stencils sometimes are overlay and I have situation like below:


Somebody know how to achieve That with stencils.

You must set the geometry queue of the moving objects after the wall. It’s just a tag “Queue”=“Geometry+1”

Ok, but then it cause another issue. I have some objects that I would like to be rendered under moving object. This all is in 2D. Please find picture below:

I want that object with higher Y position will be under moving object.