Open kisg opened 6 months ago
There are many options, depending on your needs. One way we like to do it is to define a GDExtension node class and on startup register it on /root/
Then you can call methods on this class or use signals both from inside Godot and also from the host application.
We will extend the samples with an example that shows how it can be done.
@kisg That sounds like a good approach.
Another way might be to transparently route signals back out to Swift, maybe with an easy way to register and/or filter events for performance. Going the other way, function calls are good, but I imagine marshaling/pickling might become an issue. Conversion to string or JSON is one way out, but being able to send binary buffers means media could also be exchanged. There's also tying into @observable
, so a SwiftUI button press can magically migrate into Godot world.
FWIW, the only comparable system I've come across is the Unity embedding model:
A few other embedding notes:
.onAppear
and .onDisappear
events to pause/restart the engine would make it easier to embed into existing SwiftUI controls.URLCache
and AVURLAsset
classes. Not sure how well they'll work with .pck MIME types. But having that ability opens up a whole new set of possibilities.Any update on this @kisg?
From @raminf:
Another thing that isn't clear is how to best communicate between the embedded Godot view and the native app (and vice-versa). For example, to pass a username down into the Godot view, and have the scores from the mini-games bubble back up to the main application. I can file that as a separate issue if easier to track.