Screenshot procedure changed/broken in 4.3?

Godot Version

4.3dev5

Question

Anyone able to take screenshots in 4.3? If so, did something change?

For example, this code works in 4.2, but not 4.3:

The code is not really anything different than what other people are doing, but thought I would include it.

I just get blank PNGs now

When the editor takes a screenshot, this is all it does:

You don’t need to vertically flip the image before saving the image in Godot 4, as viewports are no longer vertically flipped by default.

For me, using this script in godot-demo-projects/viewport/screen_capture at master · godotengine/godot-demo-projects · GitHub works in 4.3.beta1 (replace the demo’s script with the contents below):

extends Node

@onready var captured_image: TextureRect = $CapturedImage
@onready var capture_button: Button = $CaptureButton


func _ready() -> void:
	# Focus button for keyboard/gamepad-friendly navigation.
	capture_button.grab_focus()


func _on_capture_button_pressed() -> void:
	# Retrieve the captured image.
	var img := get_viewport().get_texture().get_image()

	# Create a texture for it.
	var tex := ImageTexture.create_from_image(img)
	
	img.save_png("user://screenshot.png")
	OS.shell_open(ProjectSettings.globalize_path("user://screenshot.png"))

	# Set the texture to the captured image node.
	captured_image.set_texture(tex)

	# Colorize the button with a random color, so you can see which button belongs to which capture.
	capture_button.modulate = Color.from_hsv(randf(), randf_range(0.2, 0.8), 1.0)
1 Like

Thanks for taking a look at this thread Calinou

The demo project does work for me in 4.3 and so does the Chore 4 demo project’s screenshot in 4.3 and 4.2 (the code I posted).

However inside my game the same code no longer works (my games use Chore as a framework). I can run the game in 4.2 and have screenshots, but running the game in any 4.3 gives blank PNGs, sometimes if I fiddle enough I will get a black PNG instead. Maybe it has to do with my game being more complex than these demo projects, or a change in how viewports are found, or something else, but something changed with 4.3 and I can’t figure out what.