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
Don't think this is a duplicate - sorry if it's already been discussed.
Cannot cast from one typed array to another using the as keyword (this used to work in older G4 betas)
As it stands there is no way of converting typed arrays to another.
This is particularly relevant when attempting to use functional tools such as map, filter etc. on typed arrays and retain strong typing.
Several workarounds exists e.g. for loops and appending where conditions are met, but it would be nice to be able to cast arrays in some way, though maybe the as keyword is not the best way as it would not be clear what happens to elements that are not of the arrays type.
Steps to reproduce
extends Node
@onready var sprites := get_children().filter(func(node): return node is Sprite2D) as Array[Sprite2D]
Attach this script and running a scene with it will get the error "Trying to assign an array of type "Array[Node]" to a variable of type "Array[Sprite2D]"."
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered:
Godot version
Godot 4
System information
Windows 10
Issue description
Don't think this is a duplicate - sorry if it's already been discussed.
Cannot cast from one typed array to another using the as keyword (this used to work in older G4 betas)
As it stands there is no way of converting typed arrays to another.
This is particularly relevant when attempting to use functional tools such as map, filter etc. on typed arrays and retain strong typing.
Several workarounds exists e.g. for loops and appending where conditions are met, but it would be nice to be able to cast arrays in some way, though maybe the as keyword is not the best way as it would not be clear what happens to elements that are not of the arrays type.
Steps to reproduce
extends Node
@onready var sprites := get_children().filter(func(node): return node is Sprite2D) as Array[Sprite2D]
Attach this script and running a scene with it will get the error "Trying to assign an array of type "Array[Node]" to a variable of type "Array[Sprite2D]"."
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered: