As of 3.x versions of Godot, there is no difference in :=
and =
in terms of performance. The only reason to use it is to prevent some type-based errors, since it helps editor to understand types. Starting from Godot 4.0+ version, :=
will also have performance boost.
There are some situations where you can use =
instead of :=
to make code a little bit cleaner. For example, Dictionary
can't be null
, so you have to return empty dictionary:
func do_something() -> Dictionary:
return {}
And to check that function did something, you need to check your return using Dictionary.empty()
method. This code can be simplified if you define return type as Variant
(variable without type):
func do_something():
return null
and then you can just check as if result != null
does that mean the engine will allocate enough memory for any and all data types?
Yes, it will allocate required memory dynamically when needed.