I have a LineEdit node, and I want to pass its contents to another node before clearing its current text. If I do that naively, what happens is that when I clear the current text, the text that the other node got is also cleared...

How do I do a "pass by copy" rather than "pass by reference"?

According to the docs, passing a string to a function should pass it by copy, rather than reference, but I am finding that is not what happens.

Can you please post some example code? I tried to reproduce it but everyting worked fine:

    func _ready():
    	var s1="Abc"
    	var s2=strtest(s1)
    	s1=""
    	print("String 1 "+s1)
    	print("String 2 "+s2)
    
    func strtest(s):
    	return s

Result: "String 1" "String 2 Abc"

18 days later

It´s dificult to say without code. Maybe you are not using correct callback from the node. If you are using a callback (signal) that actualices their state periodicaly (process, fixed_process, _input,etc...) that callback take the contents of the line-edit in the moment of actualization (every frame, on input event, etc....). If callback actualizate you variable with line-edit empty, your variable become empty, is not a problem of value-reference, your line-edit give to your callback a value, so.... what kind of method are you using to catch the text of the line-edit?

5 years later