Godot 4 Camera Tool

So as I’m working on a prototype for my own game, and of course as it gets more complex I’m running into more issues. Specifically I’ve implemented a way to project a texture to the screen to use as a pre-rendered background, but because these renders were made just for a 4:3 aspect ratio, the background will be shown in the editor/camera preview stretched to whatever that viewport size is, making it useless to preview an environment. Godot doesn’t come with any viewport options that will help me with this, so I had to go looking for something custom.

I found this Godot 3 plugin, a simple camera preview window within the editor and it seemed like a good place to build off of. Firstly I had to get it running in Godot 4 (someone else apparently ported it but the plugin was entirely broken for me), it wasn’t too hard to work out, mostly just finding the newer equivalent of classes and functions that had been deprecated. I also didn’t need any features besides the camera window so I stripped out anything I wouldn’t use.
Specifically I needed to have the preview window locked at 4:3 for the backgrounds to preview correctly so I added selectable options that would lock the window size at some different aspect ratios. Then I discovered Godot 4 has a way to create actual OS windows, so I replaced the fake viewport window with this free floating window and that’s much nicer because I can put that camera preview on a second monitor. The last major thing I was running into was that this screen projection effect was happening at all times in the 3D editor viewport meaning I couldn’t see shit when an image was being drawn over everything and that’s gonna be a big problem if I want to edit a scene while also previewing it in another window with the background enabled. For some ungodly reason Godot has visibility layers for objects already and you can use culling masks on created game cameras to filter what gets shown, but THE MAIN EDITOR CAMERA CAN’T UTILISE THAT SYSTEM? I’m sorry, I’m kinda baffled at that because of course if you have a crowded scene you need a way to hide/show certain layers in the editor. I’m sure it’ll be included some day, but until that day I have to make a tool myself, and it actually wasn’t hard to tap into the editor camera settings and have a custom menu that lets you toggle the 20 culling layers.

Anyway it all works, I’ve tested it in my own project and it’s gonna make my life a lot easier. I thought I’d chuck it on Github for anyone that might run into similar issues – here’s the link.

Overall this was a good little learning exercise, it turned out to be much easier than I thought to make custom tools for Godot because you can make them entirely within the engine using the same node and scene structures which is really cool. Having an existing plugin as a starting point was super helpful to see how they were doing things like instancing menus and connecting the inputs. I don’t imagine this will be the only custom tool I’ll need to make, so in future I’ll probably be chucking those on Github too because it’s nice to share.

Similar Posts