I'm trying to make my game-window take up a smaller space inside the main window using viewports and viewport containers, and it seems like there's a few ways to do this either using sprites, texture rects, or just the Subviewport Container.
But no matter what I've tried so far, the viewport doesn't "update" when its applied this way. I've seen other examples of this working and done a lot of googling but I'm sure I'm missing something, it's just been bugging me for a while.
Image 1: An example of the hierarchy I have set up.
Image 2: The result of said-hierarchy in-game, but my input (which does work when moving the camera around) doesn't cause the viewport to update.
Attached is two gifs, one where I can visually show what I want the small window to look like, and what it's like when the camera is a child of the character body instead of the viewport setup. The other is when I duplicate the camera under the viewport setup and place it as a child of the character body. The input is working as seen, but the smaller viewport isn't.
Quick edit: To clarify since I've also seen this noted a bit in videos and other posts, I do have the update mode of the viewport set to "Always" under the [Render Target] category.
#Shrinking viewport with Subviewport and SubViewportContainer using a 3d camera.
8 messages · Page 1 of 1 (latest)
When you make the camera a child of the viewport, its 3D transform will no longer be linked to the character body
This is because the viewport is not a 3D object, and so it does not have a 3D transform of its own. So it can't take the 3D transform of the character and propagate it to the camera. It breaks the link
Usually the way you want to use viewports is to take your entire 3D world and make it a child of the viewport. So your scene tree should look like this:
- OtherControlNodes
- SubViewportContainer
- SubViewport
- RootNode3D
- OtherNode3Ds
- Player
- CollisionShape3D
- Camera3D
- RootNode3D
- SubViewport
- SubViewportContainer
If you really want to keep your subviewport as a child in the player scene, then i would make the camera a direct child of the player and set the viewport's target camera via code. That way the camera will keep the transform from the player and will also still be sending its data to the viewport
You can use RenderingServer.viewport_attach_camera() to set the viewport's camera via code: https://docs.godotengine.org/en/stable/classes/class_renderingserver.html#class-renderingserver-method-viewport-attach-camera
You'll have to use the RID of the camera and the viewport with this method. Can't just pass in the plain old object. I think you can get the RID for both of those using their get_rid() method
Looks like cameras have get_camera_rid(): https://docs.godotengine.org/en/stable/classes/class_camera3d.html#class-camera3d-method-get-camera-rid