You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 4.2 and earlier, one could load arrays of custom object types directly from a loaded resource file in one line. E.g. var myvar: Array[SomeResource] = preload("somefile.tres").someVariable. Now, it gives the following error message: "Cannot assign a value of type Array[res://SomeResource.gd] to variable "myvar" with specified type Array[SomeResource]."
No error is brought up and code runs as usual if myvar is not statically typed. The error is also avoided if split up into two lines, e.g.
Sorry, I haven't read the issue to the end. My reply is irrelevant
ORIGINAL REPLY
In 4.2.2 there were issues with typed arrays, e.g. you couldn't do things like this:
vartyped_arr: Array[String] = []
varplain_arr: Array= ["test"]
typed_arr=plain_arr# this will failtyped_arr.assign(plain_arr) # this will be ok
I think the issue is that the const / vars above are not typed and maybe treated as Variant-s. If this is the case, then it is valid because the types of entities don't match.
I recall that I had issues with definined typed consts when used with preload() in 4.2.2 (e.g. const MY_CONST: MyType = preload("...") didn't work even if casted as preload("...") as MyType). But maybe now it's working?
Can you try to use := assignment or specify the type explicitly?
Tested versions
System information
Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 31.0.15.3742) - AMD Ryzen 5 3600 6-Core Processor (12 Threads)
Issue description
In 4.2 and earlier, one could load arrays of custom object types directly from a loaded resource file in one line. E.g.
var myvar: Array[SomeResource] = preload("somefile.tres").someVariable
. Now, it gives the following error message: "Cannot assign a value of type Array[res://SomeResource.gd] to variable "myvar" with specified type Array[SomeResource]."No error is brought up and code runs as usual if
myvar
is not statically typed. The error is also avoided if split up into two lines, e.g.Steps to reproduce
In the minimum reproduction project, the
node.gd
file will display the error. It can be reproduced byMinimal reproduction project (MRP)
Bug-Reporting.zip
Bugsquad edit: Fix formatting.
The text was updated successfully, but these errors were encountered: