Skip to content

HaxeGodot/godot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

haxe externs | editor plugin | demo | api doc | discussions

CI Haxelib Version Haxelib Downloads Haxelib License

Haxe/C# externs for Godot 3.4.5

Use the Godot engine with Haxe scripting, using the Haxe/C# target.

Using the editor plugin plugin is recommended, see the documentation on how to install it, setup a project, using Haxe scripts and building your project.

Godot will show many warnings about the Haxe generated C# code, this is because of godotengine/godot#28293.

Differences with the C# API

  • Casing
    • Variables and functions use the camelCase formating instead of C#'s PascalCase
    • Enums and types still use PascalCase
    • Constants use ALL_CAPS
    • Due to Haxe's module handling C# subtypes like Godot.Animation.InterpolationType are godot.Animation_InterpolationType
  • Export meta for variables is @:export, C# is [Export]
  • Tool meta for classes is @:tool, C# is [Tool]
  • Haxe has different keywords than C#, if the C# API use an Haxe keyword it'll be suffixed with a _
  • Typesafe signals with lambda support, for improved safety and dce support
    • signal_name become a onSignalName variable of type Signal with connect/disconnect/isConnected functions
    • Replace mynode.connect("the_signal", myHandler, "myFunction") with mynode.onTheSignal.connect(myHandler.myFunction)
    • This prevent typos on signal name, function name, and mismatch signature on the connected function or on the emitSignal function
    • Define your own signals with CustomSignal<FunctionType> and use it with the same api as the built-in signals
  • Typesafe actions
    • The project.godot file is read for its input action list and used to populate the godot.Action enum
    • You can pass an Action to functions like Input.isActionPressed eg Input.isActionPressed(MoveLeft) instead of Input.isActionPressed("MoveLeft")
    • This prevents typos on actions and give you autocompletion of the actions
    • Note: the patched functions still accept strings as normal
  • The as operator is a function on godot object, if using godot.Utils
  • Similar to GDScript you can delay a variable initialization until the node is ready by using @:onready var myNode = getNode("Path/To/Node).as(Spatial);, and myNode will only call getNode once _Ready is called

TODOs

  • Mark deprecated functions
  • Array access on Vector2, Vector3, Transform, Transform2D, Quat, Color and Basis
  • Missing types Godot.DynamicGodotObject and Godot.MarshalUtils
  • Explicit constructors
  • Function with type parameters on PackedScene.Instance, PackedScene.InstanceOrNull
  • cs.system.EventHandler_1 on GD.UnhandledException

License

The generated externs and support code are MIT licensed, the original C# externs and the Godot engine are MIT licensed.