0 votes

So I'm trying to do what's suggested here and here:
how-to-save-node-and-children-to-png, how-to-crop-screenshots-around-a-node

Now, I don't know if I just don't understand what they're saying to do, but I'm getting a blank image with my code below. (To summarize, I am just duplicating the parent node of the composite image I want to save and chucking that in an otherwise empty Viewport node. I get the image_node and viewport nodes much earlier in the code.)

var j = image_node.duplicate()
viewport.add_child(j)
j.set_owner(viewport)

var img = viewport.get_texture().get_data()
img.flip_y()

var buf = img.save_png_to_buffer()
JavaScript.download_buffer(buf,"whatever.png")

j.queue_free()

With the node structure:
-root
----Background
--------Viewport
--------image
------------ ...
--------interface
------------ ...

I've also tried fully moving the node into the Viewport node in the script, not making a duplicate, and then moving it back when I was done, but I also got a blank image from this.

(I checked to see that if I add it as a child node manually, the preview in the GUI will show the composite image (and it does), but I'd prefer to not leave my image_node in the Viewport node if I can help it, since it would break a lot to move it.)

Am I just fundamentally misunderstanding the solutions in those other answers? Any help would be massively appreciated!

Godot version 3.4.4
in Engine by (14 points)
edited by

FYI I did give up on this. I ended up just get/set pixeling all of the visible nodes onto a fresh image.

Please log in or register to answer this question.

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.