Typed arrays checks for data

Godot Version

4.3

Question

I don’t know if it’s the right place to ask, because maybe it’s a bug of gdscript.

I have a typed array defined in a node, outside of a function
var all_paths : Array[Path2D] = []
Inside the function _ready I will fill it with
all_paths.append($pathX)
If I insert something else, like $pathX\PathFollow2DX, I don’t get any error at all. The array will be simply empty.

Is that the correct behaviour? Should I get an error at compile time or during runtime instead?

It’s correct behaviour as far as I know, you just can’t append things that aren’t the correct type. You should get an error at runtime, but it won’t stop the game so you might have missed it?

Also, you can append null, even if it’s from a variable with the wrong type, so if maybe $pathX\PathFollow2DX, is null because it’s not ready yet, then it will be appended (as null)

1 Like

Actually you are right. The errors are not blocking and I didn’t notice it.
I was expecting an error earlier tbh. My bad.

E 0:00:00:0589 world.gd:8 @ _ready(): Attempted to push_back an object of type ‘PathFollow2D’ into a TypedArray, which does not inherit from ‘Path2D’.
[…]

Further reading (but I didn’t find what you said. Maybe the part “push_back” is untyped?)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.