SwiftGodotKit

0.60.2

Embed Godot into Swift apps
migueldeicaza/SwiftGodotKit

What's New

Finally it is here

2025-04-26T19:37:03Z

This is a major upgrade to SwiftGodotKit that is now using the new libgodot engine based on Godot 4.4.

Unlike the previous effort that only worked on MacOS, this one also works on iOS (not simulator), and also allows for packages and content to be embedded. This is based on the same solution that powers Godot.

I will be bringing additional code from Xogot here, but this is a baseline that unifies the various assorted branches that have been under development for too long and were hard to track down.

SwiftGodotKit provides a way of embedding Godot into an existing Swift application and driving Godot from Swift, without having to use an extension. This is a companion to SwiftGodot which provides the API binding to the Godot API.

New SwiftGodotKit

This branch contains the new embeddable system that is better suited to be embedded into an existing iOS and Mac apps and allows either a full game to be displayed, or indidivual parts in an app. This is based on the new 4.4-based libgodot patches that turn Godot into an embeddable library.

If you are looking for the old version that only ran on MacOS, check out the legacy branch.

Sample Code

MacOS Sample Code

This module contains a TrivialSample example code that shows both how to embed a Godot-packaged game (PCK files) as well as embedding Godot UI elements created programatically. This sample runs on MacOS.

iOS Sample Code

For iOS, you need a proper container, you can look at the peer SwiftGodotKitSamples project which hosts this library and a sample and deploys to iOS devices (there is no support for the iOS simulator, as Godot does not really run on those).

Using this

Just reference this module from your Package.swift file or from Xcode.

Sample

A simple SwiftUI API is provided.

In the example below, in an existing iOS project type using SwiftUI, add a Godot PCK file to your project, and then call it like this:

import SwiftUI
import SwiftGodot
import SwiftGodotKit

struct ContentView: View {
    @State var app = GodotApp(packFile: "game.pck")

    var body: some View {
        VStack {
            Text("Game is below:")
            GodotAppView()
                .padding()
        }
	.environment(\.godotApp, app)
    }
}

There can only be one GodotApp in your application, but you can reference different scenes from it.

Sausage Making Details

Check out SwiftGodotKit and libgodot as peers as well as a version of Godot suitable to be used as a library:

git clone git@github.com:migueldeicaza/SwiftGodot
git clone git@github.com:migueldeicaza/SwiftGodotKit
git clone git@github.com:migueldeicaza/libgodot

Compile libgodot, this sample shows how I do this myself, but you can pass the flags that make sense for your scenarios:

cd libgodot
scons target=template_debug dev_build=yes library_type=shared_library debug_symbols=yes 

The above will produce the binary that you want, then create an xcframework out of it, using the script in SwiftGodot (a peer to this repository):

cd ../SwiftGodot/scripts
sh -x make-libgodot.xcframework ../../SwiftGodot ../../libgodot /tmp/

Then you can reference that version of the libgodot.xcframework

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sat May 31 2025 16:46:54 GMT-0900 (Hawaii-Aleutian Daylight Time)