How do I get my gun to not go through the walls?

When I get too close to a wall the front part goes inside.
What must be done to prevent it from going through?

This is what I mean by the way.

302881-captura.png

You should do a line trace forward to the direction you are looking at for the length of your arm, if the trace hits a World Static, which is usually used for Geometry, you can play an animation where your arm goes up and set it so you can’t shoot etc.

Here is an example image of how to line trace forward of where your camera is looking, this is using the Third Person Character.

If you don’t have an animation and still want it to look really good then i guess you could have to have some kind of collision stretching out and covering your gun part, so you can’t put it through the walls.
But this will also mean that you cant move close to walls and will most likely not feel very good. This option would defintely be a ugly solution.

I imagine that there will be some way for this to have the weapon in a superior “layer” and not to pierce anything, something like this can be done in unity

I think capsule trace would be even better here