Render object on top of other objects using shader?

I am trying to render my character always in front of other objects to avoid intersections in certain places (a dual-camera solution will not work in my particular case, sorry). Setting “Depth Test” in the shader to “Always” seems to do the job except I get this see-through effect (see picture). Is there any way I can render my character on top of all other objects but avoid these artifacts on the character itself?

I’ve played around with different “Depth Test” settings but I’m not quite grasping what is happening and I’m not able to produce a good looking result. Any advice or recommended reading would be greatly appreciated!

Cheers!

Screenshot 2023-08-01 103608

Ok I’ve solved it, for those who are curious:

I used the Stencil feature to achieve what I wanted. Benefits for using stencil instead of 2 separate cameras is that your object that is always displaying on top can still cast and receive shadows from other geometry. Also, you can control which objects you want your main object to render in front of.

Unfortunately the Stencil feature is not supported in the Shader Graph so you have to generate a shader file and add the stencil code to that file. This is a bit annoying but still worth it as I can not figure out any other way to make this work.

Here’s an excellent video that describes the basics of the Stencil feature: https://youtu.be/-NB2TR8IjE8

To make this work, add this code to the object to be in front (in the shader file):

Stencil
{
Ref 2
Comp Always
Pass Replace
Fail Replace
}

And add this to the object(s) which should always render behind the above object:

Stencil
{
Ref 2
Comp NotEqual
}

That’s it, pretty simple but works like a charm.