Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design patterns for communicating with the embedded Godot app #5

Open
kisg opened this issue May 24, 2024 · 3 comments
Open

Design patterns for communicating with the embedded Godot app #5

kisg opened this issue May 24, 2024 · 3 comments

Comments

@kisg
Copy link
Contributor

kisg commented May 24, 2024

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.

@kisg
Copy link
Contributor Author

kisg commented May 24, 2024

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/ as if it was an autoloader singleton.

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.

@raminf
Copy link

raminf commented May 24, 2024

@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:

  • Tying into UIViewController's .onAppear and .onDisappear events to pause/restart the engine would make it easier to embed into existing SwiftUI controls.
  • Not sure how hard this will be, but it would be good to have a way to delete and re-instantiate the GodotView to free up memory at runtime. The Unity embed mechanism says you can delete it, but you won't be able to re-create it. Only way is killing the app!
  • Finally: be good if there was an easy way to load a .pck file from a remote URL. There's already 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.

@pluviamtonitrus
Copy link

Any update on this @kisg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants