Having to re-learn stuff after upgrading to Godot 4.x. I can declare an int with

@export var spoon:int = 224 # or 
@export var spoon:= 224

However, I can't seem to use the same for a vector 2: @export var variablename: type = value

@export var canvas_size:= Vector2(224, 256)  # works
@export var canvas_size:Vector2 = (224, 256) # doesn't work

Results in Error: expected closing ")" after grouping expression

Where am I going wrong?


1 Answer 1


Yes, this does not work

I can do little more than reiterating what you discovered. This does not work:

@export var canvas_size:Vector2 = (224, 256) # doesn't work

You would have to write this:

@export var canvas_size:Vector2 = Vector2(224, 256)

But why when you can write this:

@export var canvas_size := Vector2(224, 256)

I want to point out that the proposed syntax is not really equivalent to the int literal, given that the Vector2 type (despite being built-in and value type) is not primitive, but composite. So it seems to be closer to Array ([]) and Dictionary [{}] initializers.

Why this does not work

Why does that syntax not work? Because nobody implemented it. Features start up not existing, and somebody has to program them.

Currently the parser only uses what precedes the open parenthesis to decide how to interpret the expression... But, for this syntax, deciding how to interpret the parenthesis would have to be delayed until it knows if there is a comma or not...

Furthermore, how many commas, given that the type would depend on the number of elements if it will support Vector3 and Vector4.

On the same order of ideas, the integer vectors (Vector2i, Vector3i and Vector4i) throw another wrench on this. For example, since in (224, 256) all the elements are ints, I would expect a Vector2i instead of a Vector2 (which uses floats).

I'm not saying it can't be done, it can be done. I'm postulating that it might not be worth it (a lot of effort for little gain). But don't take me as gatekeeper...

You can write a proposal if you really care about this feature, make your case.

No, this is not new in Godot 4

By the way, I'll point out that barring @export it is the same situation in Godot 3, it would be like this:

export var spoon:int = 224 # works
export var spoon:= 224 # works
export var canvas_size:= Vector2(224, 256)  # works
export var canvas_size:Vector2 = (224, 256) # doesn't work

Yes, Godot 3 had typed variables.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .