-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Export arrays in singleton end up shared if initialized to same value (fixed in master
)
#20436
Comments
I could reproduce the issue, here's a simpler example: # g.gd, defined as "g" singleton
extends Node
export var arr1 = []
export var arr2 = [] # main script
extends Node
func _ready():
print(g.arr1, " ", g.arr2)
g.arr1.append(1)
g.arr2.append(2)
print(g.arr1, " ", g.arr2) Output:
If I remove So it seems like The bug also happens if both are initialized to the same non-null value, e.g.: # g.gd, defined as "g" singleton
extends Node
export var arr1 = [3]
export var arr2 = [3] Output:
If the |
I could reproduce the issue on 3.0.5-stable and in the current master branch (f778bd8). |
I removed the keyword |
Just tested when asked by @bojidar-bg: if So it's buggy only in the singleton + export + same initialization case. |
Can you still reproduce this issue in the current master branch? |
Just downloaded Godot v3.1.beta2.official and tested, nothing has changed: |
Same issue in Godot v 3.1.2-stable in linux. Remove "export" solve the issue. Godot version: OS/device including version: |
Similar issue in Godot_v3.2.1-stable_win64. However, it applies to non-singleton scripts as well. |
extends Node2D
export (Array) var arr_A = []
export(Array) var arr_B = []
func _ready():
for i in range(10):
arr_A.append("A")
#arr_B.append("B") # even bypassed it appends
print(arr_B) Output: [A, A, A, A, A, A, A, A, A, A] 3.2.2 beta3 |
|
I will look into this on my time off from FBX over the weekend. |
Based on this info, it seems like an issue with type inference where it has two sources of type. Here both are Array but that seems inconsequential. Update: @boruok I couldn't get case 4 to work if both are like that.
|
Quick look at the code: godot/modules/gdscript/gdscript_compiler.cpp Lines 376 to 386 in 3be9c74
Now, this does not happen for all empty arrays. This is so because godot/modules/gdscript/gdscript_parser.cpp Lines 1740 to 1753 in 3be9c74
This function is called through the place parsing godot/modules/gdscript/gdscript_parser.cpp Line 4920 in 3be9c74
This does not happen in case 3 godot/modules/gdscript/gdscript_parser.cpp Line 5025 in 3be9c74
|
This is fixed by #41983 in 4.0, but a fix is still needed for 3.2, so reopening. |
master
)
Just ran in to this with v3.5.stable.official [991bb6a] although it was in a Resource, not a singleton.
Simply removing the assignment was enough to make it work correctly.
|
It's been 4 years since this issue was discovered. And it is still there. Godot v3.5.stable.official [991bb6a]: extends Node2D
export (Array) var arr_a := []
export (Array) var arr_b := []
func _ready() -> void:
for _i in range(10):
arr_a.append("A")
arr_b.append("B")
print(arr_a) Prints:
If it was really fixed in Godot 4, is there any plans on backporting it to 3.5? |
@Exerionius I don't think it's a matter of backporting. For 4.0 GDScript was totally rewritten (parser, analyzer, compiler etc.), meaning in 3.x it works way differently. Hence it likely needs a dedicated fix, not a backport. |
I found that if you really need a default value, store in another var and pass it like this, will fix the issue
But if you change var to const, then the issue came back,,, very strange
|
Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.
Godot version:
Godot v3.0.5.stable.official.6a88e22 win64
OS/device including version:
Windows 10 Pro v.1803 (on 2 different pc)
Issue description:
Loading values in a two-dimensional array has different results if the array is local or global.
On a new project, I added a script (g.gd) as autoload-singleton enabled with the following code:
extends Node
I create a new scene assigned as main scene on project setting, on the root node added a script with the following code:
The resulting output is:
Is it a bug or my poor knowledge of gdscript (python)?
Thanks for the attention.
The text was updated successfully, but these errors were encountered: