If you can see the above image, you will note that the subviewport is accurately displaying the revolver AND the 3D world is still visible. If you are trying to use a subviewport to prevent weapon clipping in Godot 4.x, and you see the below image (or similar to it), then you have run into the subviewport issue I am referring to.

If all you see is your weapon, in this case my home made revolver, and the environment background, but no 3D world, you may have forgotten to turn on “transparent BG”, but if you have and you still see this, you probably have the same issue I did. Fortunately, there is a work around.

While following a Udemy course on building 3D games with Godot, the instructor had us create a subviewport and use a camera in that subview to look at the weapon, and keep the player camera from seeing the weapon. On his screen, it worked like a charm. In the tutorial video, it worked like a charm, but in my Godot world, it was not working at all.

I rewatched the lessons and made sure to check “transparent BG” for transparent backgrounds. I searched the web and found people saying you need to turn off SSR in your environment variables. But it was already off. I found other people saying that it is an issue in compatibility mode, and that there was not a good work around. Other people were using the alpha scale to “cheat” and show a weapon that was partly transparent just so you could see everything.

Fortunately, after playing around for an hour, I figured out a much easier work around.

You probably have a setup like mine: SubViewport Container –> SubViewport –> Camera3D (we will call it weaponCamera for this article). In which the SubViewport has “transparent BG” selected. But when your player is instantiated in your level/world, the environment and the weapon is all you see in your SubViewport view of the world. If that sounds like you, then here is what you need to do:

Go to your weaponCamera (the one in the SubViewport) and give it an new environment. I tried copying the level environment, but that didn’t work. I also saved the level environment and tried to load that and it didn’t work. I just made a new environment, NOT choosing sky, set the color to match, and that worked great. However, there is a catch…..

If you do this, your gun/weapon doesn’t always get lighter or darker when you walk under items or out into a bright light. So this is only a half way fix for the battle. But this does work well enough to do the job.

The actual problem is with your World Environment. If your world environment uses “sky” then that causes all the issues. So, if you don’t want to do the work around I mentioned above, a different workaround is to set a different option for your world environment that doesn’t use “sky”, like canvas or custom color, etc. Choosing any of these options and you will not need a custom world environment for your weaponCamera. This keeps everything “together” better, but you lose what I consider to be one of the best environment options, which are the sky settings.

Anyhow, I hope that is helpful for the next person trying to web search an answer to this problem!

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *