How to Fix Weapon Clipping in Unity

Поділитися
Вставка
  • Опубліковано 20 лип 2021
  • I was messing around with this little FPS that I have apparently started writing - and I came across a clipping issue, whereby walking into an object causes half the weapon to disappear. So I wanted to see how to the Unity team solved this issue, and having a look at Unities FPS Microgame it seems they took the approach I explained in the video.
    ___________________________________________________
    Subscribe: / @tvtig
    ____________________________________________________
  • Наука та технологія

КОМЕНТАРІ • 61

  • @Keegadorf
    @Keegadorf Рік тому +78

    If this isn't working for anyone, your project might be using URP (Universal Render Pipeline). If this is the case, you need to set the weapon camera "Render Type" to "Overlay", and then on the main camera, under "Stack", click + under the cameras tab, and add the overlay weapons camera to the stack.

    • @jakes-dev1337
      @jakes-dev1337 Рік тому +4

      God send thank you.

    • @Ledex2107
      @Ledex2107 Рік тому +1

      Thank you.

    • @FAKKER_rap
      @FAKKER_rap Рік тому +2

      where you find this option?? its not anywhere in the inspector of cam

    • @w0tnessZA
      @w0tnessZA Рік тому +1

      You're a fucking legend dude! Thank you so much!

    • @juanalfonsosototorres2319
      @juanalfonsosototorres2319 Рік тому +1

      Thank youuuu, you save me from working on a scrpt to fix it

  • @NA-jy4zd
    @NA-jy4zd 2 роки тому +30

    im on unity 2020.3.31f1, set the weaponcam clear flags to depth only for it to work

    • @buddyroach
      @buddyroach Рік тому

      i did this and it showed up in the little window in the editor but when i went to play the game, it didnt show up. and when i exited, it was no longer in the window in the preview.

    • @martyn974
      @martyn974 Рік тому

      Thank you!!

    • @equiaux_music
      @equiaux_music Рік тому

      This one solved my problem thanks

    • @derboss66
      @derboss66 11 місяців тому

      thank you

    • @beastguyvv
      @beastguyvv 3 місяці тому

      ur a god thx

  • @jacqbotes8382
    @jacqbotes8382 2 роки тому +10

    good ol' smoke and mrrr

    • @Tvtig
      @Tvtig  2 роки тому +8

      Lol at least I know you watch right till the end.

  • @buddyroach
    @buddyroach Рік тому +1

    i dont see Background Type in the camera settings. where is it?

  • @tweenky
    @tweenky Рік тому +3

    Thank you.

  • @sycho_zer0edits451
    @sycho_zer0edits451 7 місяців тому

    Thank you so much its working fine!

  • @FAKKER_rap
    @FAKKER_rap Рік тому +2

    if it renders only one of them - make sure to adjust the depth of the weapon cam so they are not the same

  • @H-jn5gt
    @H-jn5gt Місяць тому

    Old video I know, but is there anyway to make this work for HDRP?

  • @ardaaydin4771
    @ardaaydin4771 Рік тому

    Short and clear.

  • @redragon1229
    @redragon1229 Рік тому +5

    Yeah, it's a classic solution. The problem is that the weapon will not receive any shadows from the world, as the world geometry is on another layer (

    • @stylie473joker5
      @stylie473joker5 Рік тому +1

      Players won't care about that honestly, they'd lose the immersion if the weapon was clipping

    • @redragon1229
      @redragon1229 Рік тому +1

      @@stylie473joker5 Cascade shading really adds detail as probelit is too basic. I'm sure there's a better solution to this problem, it's not just clipping vs this.

    • @stylie473joker5
      @stylie473joker5 Рік тому

      @@redragon1229 I found a solution in HDRP i'm using two Custom passes to draw the weapon on top of everything while still keeping post processing and other details (as always remove the weapon layer from the camera and add it to the passes to make them render only the weapon), the depth test of one of the passes has to be set to "Always" while the other to "Less equal", and sorting to "Everything" for both; also the injection point has to be "After opaque depth and normal" or SAAO will render on top of the weapon when the weapon is on top of an object with SAAO.
      I don't know if this method is perfect but so far it works great hope that helps.

    • @redragon1229
      @redragon1229 Рік тому +1

      @@stylie473joker5 Awesome! A video tutorial would be perfect.
      I also have an idea - In continuation to this video: duplicate the entire level geometry and set "Only shadows" in the MeshRenderer + put it on the "weapon" layer. It will significantly increase DrawCall number, so you need to combine all the meshes into one - it's pretty simple.
      Very hacky but should work

  • @Mazy113
    @Mazy113 2 роки тому +2

    what if i dont have enviroment settings to change background type in my Weapon Camera?

    • @AZASeraph
      @AZASeraph 2 роки тому

      Same

    • @Banaaani
      @Banaaani 2 роки тому +2

      I believe change Clear Flags to Don't Clear

  • @alisharoz8303
    @alisharoz8303 2 роки тому +7

    game dev is all about smoke n mrr :D

  •  2 роки тому

    Thanks man

  • @diemekalombo8151
    @diemekalombo8151 Рік тому

    Thankyou So Much

  • @dhashikaramgolam3182
    @dhashikaramgolam3182 Рік тому

    Very cool 😊

  • @Android-jz2yh
    @Android-jz2yh Рік тому

    One thing is that when I drop the weapon on the ground and go around a corner I can still see the weapon

    • @imir_
      @imir_ 11 місяців тому +1

      Make it change layer if it's dropped

  • @HellBound_101
    @HellBound_101 Рік тому

    That's fine, but when I run it's like the weapon duplicates. Can it be fixed?

    • @redragon1229
      @redragon1229 Рік тому +1

      Disable "Weapons" layer rendering on the main camera

  • @waitezin
    @waitezin Рік тому

    thank you

  • @CodeOrDieUK
    @CodeOrDieUK 2 місяці тому

    ty

  • @arunachalpradesh399
    @arunachalpradesh399 Місяць тому

    this is the worst way for performance hit. unless you targetting high end devices.

  • @HiImKyle
    @HiImKyle Рік тому

    I hate that I google for HDRP and this shows up. Like it's great that you can do this but it's annoying as hell I can't do this on HDRP..

    • @Tvtig
      @Tvtig  Рік тому

      Hey man - sorry about that, have you taken a look at this article? www.intetic.com/blogs/unity-hdrp-render-object-on-top-of-everything/

  • @kaszana9698
    @kaszana9698 Рік тому

    more zooms please...

  • @IluXa4000
    @IluXa4000 3 місяці тому

    That's not a good solution, you would probably want to do smth else with this. Why is this bad? Cause u don't see clipping, but it happens. Imagine that now u may want to shoot enemy at close range, but weapon will fall into enemy collider and your shots won't be registered, cause bullet collision doesn't work from inside of enemy collider.
    The proper way to do this is through creating a custom shader for the materials on the weapon to always be rendered on top, or to move the weapon out of the way when you're close to a wall via a raycast check

  • @deslangan3157
    @deslangan3157 Рік тому

    "game dev is all about smoking marijua-"

  • @equiaux_music
    @equiaux_music Рік тому

    i agree as a stoner

  • @lazikbro12
    @lazikbro12 Рік тому

    nope not working

  • @Ganymede2076
    @Ganymede2076 Рік тому

    Bruh just enable the mesh collisions and job done