Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript : default value of an exported variable can be modified at run time #41953

Closed
ChickenStorm opened this issue Sep 10, 2020 · 1 comment · Fixed by #41983
Closed

GDScript : default value of an exported variable can be modified at run time #41953

ChickenStorm opened this issue Sep 10, 2020 · 1 comment · Fixed by #41983

Comments

@ChickenStorm
Copy link

Godot version: v3.2.2.stable.official

OS/device including version: Windows 8.1

Issue description:
When using export var variable : Type = default_value, if default_value is a reference, it can be modified at run time. At the creation every variable will point to the same value. It means that one can modify variable of other instances of the class. It will also affect the value of variable at the creation of a new instance.

Steps to reproduce:

minimal code to reproduce

class_name CustomObject
extends Object

export var dict : Dictionary = {}
extends Node


func _ready():
	var a = CustomObject.new()
	a.dict["key"] = "test"
	a.free()
	var b = CustomObject.new()
	print(b.dict)
	b.free()

output : {key:test}

Minimal reproduction project:
minimal-project-export-default.zip

@akien-mga
Copy link
Member

Related to #20436, might be duplicate of another issue but can't find it right now. CC @ThakeeNathees @vnen @bojidar-bg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants