godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.93k stars 3.21k forks source link

Document unexpected behavior when exported arrays are shared #5640

Open me2beats opened 2 years ago

me2beats commented 2 years ago

Your Godot version: 3.5 beta, 3.4 stable

Issue description:

class Test:
    extends Node
    export var x = []

func _ready():
    var test1 = Test.new()
    var test2 = Test.new()
    test1.x.append(0)
    print(test2.x)

https://github.com/godotengine/godot/issues/48038

This is unexpected because I assume exported vars are kinda regular vars (properties), not constants.

URL to the documentation page (if already existing): gdscript_exports is the right place to clarify this behavior imo https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html

zacryol commented 2 years ago

The specific issue, as of the last time I checked, was:

If an export var Array/Dict has a default value set in code, then any instance that does not have that value changed to something else via the editor will share a reference to that array/dict.

Seems to be fixed in master though.