The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

i have a viewport node where transparent_bg = true

var img = get_node("viewport").get_viewport().get_texture().get_data()

the viewport texture background are transparent in the editor, but black when its saved.
any idea?

in Engine by (200 points)

Have you checked the texture data to see whether it has alpha data?

Got it, i had to convert the format

2 Answers

+6 votes
Best answer

VIEWPORT.get_texture().get_data() returns an Image in the format, FORMAT_RGBAH.
You can check this by using IMAGE.get_format()

It will return 15, which is the enum value for IMAGE.FORMAT_RGBAH
When you save it with save_png(), all the transparent pixels are black.

You can simply convert the image to FORMAT_RGBA8, and then when you save it, it will preserve its transparency.

var my_img : Image = my_viewport.get_texture().get_data()


by (240 points)
selected by
+4 votes


by (200 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.