See Docs: Using Custom Types

Overview

Creating a subclass of a Godot type involves a few steps:

  1. Subclassing an existing Godot type with the usual Swift syntax.
  2. Registering your type with Godot, so users can create instances of it and configure it from the user interface.
  3. Augment the type with your own custom behaviors.
  4. Expose your properties, methods and signals to the Godot Editor.
  5. Setting up your SwiftGodot GDExtension by defining it in The .gdextension file

Type Levels

A custom swift type can be registered at different levels. See docs for GDExtension.InitializationLevel using the macro initSwiftExtension(cdecl:coreTypes:editorTypes:sceneTypes:serverTypes:) (see docs).

When Godot initializes your extension it does so in stages and you get a chance to register the types that you want to expose to the Godot engine for each stage (GDExtension.InitializationLevel).

For example, to initialize a Swift extension to Godot with some custom types to use in the editor, and some other types to use on the scene.

class MySprite: Sprite2D { ... }
class MyControl: Control { ... }
 
 
#initSwiftExtension(cdecl: "myextension_entry_point",
                    editorTypes: [MyEditorPlugin.self],  
                    sceneTypes: [MySprite.self, MyControl.self])