Godot Version
Godot 4.2.2
Question
Hello !
I’m becoming mad on something that seems so simple.
I need to do a deep copy of a property of an object.
To summarize, I made this little example :
Thing.gd
extends Object
var param = 100
Main.gd
extends Object
@export var thing_scene = preload(“res://Thing.tscn”)
var thing
var copy
func _ready():
thing = thing_scene.instantiate()
thing.param = 200
copy = thing.duplicate()
print("thing param : ",thing.param)
print("copy param : ",copy.param)
And the result is :
thing param : 200
copy param : 100
I always get the default value of the property but not the actual value.
Other things I tried :
If I try copy = thing.duplicate(true) I get "Invalid get index ‘param’ ". (sad, the documentation says that’s the way to make a deep copy)
If I try thing.param.duplicate() I get “Invalid call. Nonexistent function ‘duplicate’ in base ‘int’.”
And I didn’t found any other way to duplicate than the duplicate() method.
If that matter, in my game, it’s the direction (so a Vector2) of a CharacterBody2D that I try to duplicate because I have to register the direction of an object before it changes to adapt the direction of other objects.
Please, how can I deep copy a property ?
Thank you for your reading !