0 votes

I have a painting game, I want to save the player's painting/viewport as a png.
Here's my code:

func save_painting():
    var masterpiece = get_viewport().get_texture().get_data()

    masterpiece.flip_y()
    masterpiece.convert(Image.FORMAT_RGBA8)

    var save_path = "res://Minigames/paint/input/Masterpiece.png"

    masterpiece.save_png(save_path)

But I keep getting this error log:

ERROR: Can't save PNG at path: 'res://Minigames/paint/input/Masterpiece.png'. at: save_image (drivers/png/resource_saver_png.cpp:56) - Condition "err" is true. Returned: err

It works ok in Godot but once exported it causes a crash. Tried for days to solve this myself to no avail. Please help!

Thank you!

Godot version 3.3
in Engine by (31 points)

Do you have write permission to said location? Try running the exported game as administrator and see if that makes any difference.

1 Answer

0 votes

"res" folder only exists for a project. You need custom folder after exporting, the one that every user has. Usually it is user/appdata, but You can pick any real system path

by (7,301 points)

Thank you, I saved it at path user://masterpiece.png. It saves, and appears in the file manager, but when I try to load it as sprite texture in godot it gives this error message:

ERROR: Resource file not found: user://masterpiece.png.
   at: _load (core/io/resource_loader.cpp:275) - Condition "!file_check->file_exists(p_path)" is true. Returned: RES()

This is how i load it in godot:

$Sprite.texture = load("user://masterpiece.png")

Wracked my brain for days. Still confused.

Might you know why this error appears?

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.