Search code examples
variablestypesoption-typegodotgdscript

Is there a way for variables to have a few types in GDScript


I know GDScript has dynamic typing, but I was wondering if there was a way to give a variable only a few types it can have. Something like this:

var myVar : int : string = 12;
myVar = "Hello";

Does it have a feature like this?


Solution

  • No. This is not supported in GDScript.

    There is a relevant proposal: https://github.com/godotengine/godot-proposals/issues/737 (The syntax would be var myVar: int|string). However, it is not part of the Godot 4.0 milestone.