How do I duplicate a resource and set its contents by code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Moot Point

I have a basic resource with a script that contains a few export Strings and an image texture. How can I duplicate it with a new image or modified strings by code?

:bust_in_silhouette: Reply From: Bernard Cloutier

Resource has a duplicate method, so do this:

var cloned_resource = my_resource.duplicate()
cloned_resource.my_string1 = "stuff"
cloned_resource.image = load("res://my_image.jpg")