weapon clipping

Is there a way to prevent a weapon from going inside a wall when you get to close WITHOUT changing the camera scale or the capsule radius?I cant seem to find anything online and Disable Depth Test only works on translucent materials.

Have the collider on the weapon push it inside the player / move it to the side.
Or go the extra mile like this:

I did something similar by rotating the bones when the gun gets to close,its not perfect but does the job,still i think there can be a better solution if i could turn a translucent material into full opaque and use the depth test option.