How to fix the Gun Model clipping into walls?

I’m new to gamedev. I am working on a FPS. My gun model clips into the wall when I walk into it.

One method that I was told would work is to have the gun on a different renderlayer. I’m not sure on how to do this though.

If this method can be used to solve this problem, how can I implement it? Otherwise, what is another method to solve this problem?

EDIT: I am preferably looking for a method by which the gun is always facing forward, even when up against a wall.

Easiest is animation that either lowers gun or raises it up, just like human would do going close to wall.

I seen plenty of tutorials or videos with that, just google it.

here is one solution (not anim based)

i asked uncle google for: “unreal fps clipping weapon”

While that is an easier way of doing it, I was hoping for a way to fix the clipping without having the gun be raised like in that video. I was hoping for the way to implement the different Renderlayer as I wanted the gun to always be pointing forward.

You probably can do it with postprocess material.