gogdc reference

How gogdc binds methods in our Go files to entry points that Godot can call through GDNative is controlled by specially formatted comments, in this section we will present all of them including the properties struct fields, this section complements the information available in Class Auto Registration / Overview.

Class Registration

Class auto registration has two forms, passthrough or aliased

check class autoregistration for more details


type MyGoStruct struct{}


//godot::register as Enemy
type MyEnemyGoType struct{}

Class Constructor and Destructor

Go does not have a concept of value constructor or destructor but we can bind any Go functions to our Godot class even if the function is not a method of the registered class

func New() *MyGoType {
    gt := MyGoType{}
    return &gt

check constructor and destructor for more details

Class Methods

Only annotated (or commented) methods get exported an made available to Godot, methods as classes can be exported as passthrough or aliased

check methods for more details

unexported Go methods are ignored by gogdc and they are not exported into Godot even if they are decorated


func (gt *MyGoType) MyMethod() gdnative.Variant {    
    return gdnative.NewVariantWithString("Hello Godot!")


//godot::export as my_method
func (gt *MyGoType) MyMethod() gdnative.Variant {    
    return gdnative.NewVariantWithString("Hello Godot!")


Properties doesn’t use comment annotations but struct field tags. Note that these tags are not evaluated on runtime as gdnative-go does not uses the reflect at all in runtime.

Properties are registered as they are encountered in the exported classes, struct field tags are used to set options to them, the four tags that can be configured are rset_type, usage, hint and hint_string each one of them corresponding to their Godot counterparts

rset_types (Method RPC Mode) possible values

  • disabled
  • remote
  • master
  • puppet
  • slave
  • remotesync
  • sync
  • mastersync
  • puppetsync

hint possible values

  • none
  • range
  • expRange
  • enum
  • expEasing
  • length
  • spriteFrame
  • keyAccel
  • flags
  • layers2DRender
  • layers2DPhysics
  • layers3DRender
  • layers3DPhysics
  • file
  • dir
  • globalFile
  • globalDir
  • resourceType
  • multilineText
  • placeholderText
  • colorNoAlpha
  • imageCompressLossy
  • imageCompressLossless
  • objectId
  • typeString
  • nodePathToEditNode
  • methodOfVariantType
  • methodOfBaseType
  • methodOfInstance
  • methodOfScript
  • propertyOfBaseType
  • propertyOfInstance
  • propertyOfScript
  • max

all these are case sensitive and must be written in the same camel case

usage possible values

  • storage
  • editor
  • network
  • editorHelper
  • checkable
  • checked
  • internationalized
  • group
  • category
  • storeIfNonZero
  • noInstanceState
  • restartIfChanged
  • scriptVariable
  • storeIfNull
  • animateAsTrigger
  • updateAllIfModified
  • default
  • defaultIntl
  • noEditor

all these are case sensitive and must be written in the same camel case