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

Export game as embeddable iOS view to easily use non-Godot code (Android already supported) #1473

Open
bfelbo opened this issue Sep 7, 2020 · 39 comments

Comments

@bfelbo
Copy link

bfelbo commented Sep 7, 2020

Describe the project you are working on:
Multiplayer game for iOS and Android

Describe the problem or limitation you are having in your project:
Due to the social nature of our game, we need to:

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Godot added support for embedding your game inside an Android app and it would be amazing if Godot added support for iOS as well.

A few benefits:

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
Similar to godotengine/godot#39855 for Android, it would be possible to export your game as an embeddable iOS view.

A developer would create their own Android/iOS app from scratch and use the Godot embeddable view. Inside the app, the Godot view could be displayed for the actual gameplay. For instance, consider the popular mobile games Brawl Stars, Fortnite, and PUBG. The developers could code up all the UI, app permissions, ad tracking, etc. in any language and then use Godot once the user clicks "Play" and enters the actual gameplay.

One way to think of the current default Godot app exports is that they're a embeddable view + a wrapper. The view has all the core functionality and the wrapper handles things like setting the right permissions in the AndroidManifest.xml. If this was separated, it would be easy for anyone to export a complete app or to just use the embeddable view depending on their use case.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Not that I know of.

Is there a reason why this should be core and not an add-on in the asset library?:
Porting/exporting is best handled in core and this proposal would alleviate the need for many other core proposals (see linked issues above).

EDIT:
Updated to split out documentation and focus on iOS support based on @m4gr3d's suggestion.

@Calinou
Copy link
Member

Calinou commented Sep 8, 2020

This will be supported for Android in 4.0 since godotengine/godot#39855 was merged.

@bfelbo
Copy link
Author

bfelbo commented Sep 8, 2020

Amazing! Then this proposal can be focused on adding support for iOS and documentation on how to use it 😊

@m4gr3d
Copy link

m4gr3d commented Sep 14, 2020

@bfelbo Quick clarifications:

  • Being able to use Godot as a library is already supported starting with Godot 3.2.0 (though using the latest stable version, 3.2.2, is recommended as it addresses several issues). There is not a lot of documentation since it's an advanced feature but you can take a look at the project structure when Godot installs an Android build template in the res://android/build directory.
  • The PR you linked to above (PR Enable the ability to use Godot as a subview within an Android app godot#39855) builds on that capability to enable embedding Godot as an Android fragment. The feature has been merged but it's still in development (mostly testing and bug squash if any) and is targeted for Godot 3.2.4.

So if you just need the ability to embed Godot as a library on Android with Godot taking over the full screen when invoked, you should be good to go with the current stable version.
If you need the ability to embed/restrict Godot to a specific view, then that feature will be available in Godot 3.2.4. I'd still recommend starting the process of integrating the Godot library in your target application to get familiar with the process.

And since this is an open source project, any feedback, learnings, documentations or examples you'd like to share or contribute back would be much appreciated :)

@m4gr3d
Copy link

m4gr3d commented Sep 14, 2020

@bfelbo Would you mind splitting this proposal in two. The iOS portion remains, so there should be a proposal focusing on the iOS side of the equation.
For the Android side, based on the current proposal, only the documentation portion is missing, so the updated proposal should reflect that.

@bfelbo bfelbo changed the title Export game as iOS/Android libraries to easily use non-Godot code Export game as iOS library to easily use non-Godot code (Android already supported) Sep 15, 2020
@bfelbo bfelbo changed the title Export game as iOS library to easily use non-Godot code (Android already supported) Export game as embeddable iOS view to easily use non-Godot code (Android already supported) Sep 15, 2020
@bfelbo
Copy link
Author

bfelbo commented Sep 15, 2020

@bfelbo Would you mind splitting this proposal in two.

Definitely! I've separated out the documentation into https://github.com/godotengine/godot-proposals/issues/1518.

If you need the ability to embed/restrict Godot to a specific view, then that feature will be available in Godot 3.2.4.

Thanks for the detailed explanation. It's really cool that it's already possible to do this on Android!

And since this is an open source project, any feedback, learnings, documentations or examples you'd like to share or contribute back would be much appreciated :)

Yes, we'd love to contribute in any way we can :)

@naithar
Copy link

naithar commented Sep 16, 2020

This should be possible with new iOS plugin system once or if it gets merged. Plugin Proposal, 4.0 PR, 3.2 PR.
In PR for 4.0 I've also gave some kind of example for using native UI. I guess integrating it with React Native should be possible too.
I also plan to make AppDelegate class more extendable as well as enabling ARC usage. This should give a more easier access to PushKit and RemoteNotifications as well as simplify iOS specific implementation.


As for making Godot embeddable.
It should probably not be an embeddable UIView, but UIViewController, which should give some control over app lifecycle.
Switching to NSNotification instead of AppDelegate method would be needed, but some things might be missing there, I'm not entirely sure.
Also Godot uses it's own main method, so moving it into iOS template is required, otherwise iOS application will get a duplicated symbols error.
This should be pretty much all the work needed on platform side. But with current 3.2 state I would probably wait for some refactoring done first.

@bfelbo
Copy link
Author

bfelbo commented Sep 16, 2020

Thanks for the detailed explanation @naithar! Makes sense that it might require some refactoring first before working on making Godot embeddable.

@bfelbo
Copy link
Author

bfelbo commented Oct 31, 2020

I just saw that 3.2.4 will include Android embedding support 🎉 Would be awesome to also have it on iOS in the near future so this can be used by all the devs building cross-platform mobile apps.

@naithar, what kind of refactoring do you think should be done before working on this? Anything I can help with?

@naithar
Copy link

naithar commented Oct 31, 2020

@bfelbo most of the work that are needed was already merged (godotengine/godot#42459, godotengine/godot#42582 and some other PRs), only PRs with fixes are left, like godotengine/godot#42648. Maybe Motion manager should also be moved in separate class, like joypad, but I'm not sure.

I'm also waiting for godotengine/godot#41230 to be merged. It'll allow to build plugins for iOS without rebuilding the whole engine.

After that I think it'll be safe to implement embedding Godot game into another iOS application.

@bfelbo
Copy link
Author

bfelbo commented Dec 25, 2020

@naithar Happy holidays! It's great to see that the blocking PRs you mentioned have been merged. I'm sure more changes will be needed to allow exporting as an embeddable iOS view, but it's nevertheless incredible to see the rapid progress! Thanks so much for your good work! :)

@leacoleaco
Copy link

Is it possible to implement a "godot-widget" for flutter ? :)
like this open source lib: https://pub.dev/packages/flutter_unity_widget

@naithar
Copy link

naithar commented Feb 2, 2021

Is it possible to implement a "godot-widget" for flutter ? :)
like this open source lib: https://pub.dev/packages/flutter_unity_widget

Once/If this proposal is implemented, it should be possible to some extent.

@bfelbo
Copy link
Author

bfelbo commented Jul 13, 2021

@naithar, seems like implementing this could involve some breaking changes. Would it make sense to include this in 4.0?

@naithar
Copy link

naithar commented Jul 13, 2021

seems like implementing this could involve some breaking changes

I guess it can. But it mostly depends on implementation. I can't really say for sure, since I haven't really touched this topic.
What I've came up with will probably involve creating separate export template which will include .a or xcframework file with headers which will provide integration API. But I can't really tell if it will work for now.

Would it make sense to include this in 4.0?

Making it 4.0 only will probably remove the need to check for breaking changes as long as it doesn't break anything else :)

@bfelbo
Copy link
Author

bfelbo commented Jul 13, 2021

Making it 4.0 only will probably remove the need to check for breaking changes as long as it doesn't break anything else :)

Sounds good, that should dramatically reduce the testing effort. Do you know what's the process for marking this issue as part of the 4.0 GitHub milestone? :)

@Calinou
Copy link
Member

Calinou commented Jul 13, 2021

Sounds good, that should dramatically reduce the testing effort. Do you know what's the process for marking this issue as part of the 4.0 GitHub milestone? :)

Setting a milestone on a proposal means that we commit to delivering the feature in that version, and I'm not 100% sure if anyone will be able to make this in time for 4.0 (whose release is expected in 2022).

@bfelbo
Copy link
Author

bfelbo commented Aug 11, 2021

Thanks for clarifying @Calinou. Makes sense to avoid setting the milestone to prevent committing to including this.

@naithar, if you have time, it'd be awesome to include this as a 4.0 feature, which should also simplify testing as you mention :)

@dboylx
Copy link

dboylx commented Feb 6, 2022

is it available now?

@Calinou
Copy link
Member

Calinou commented Feb 6, 2022

@dboylx No, not yet. There is no ETA for implementing this feature either, as no contributor is available to work on it.

@dboylx
Copy link

dboylx commented Feb 9, 2022

ok, thankyou , plz tell me when it's ok

@PhungVanHoa
Copy link

Any updates?

@Calinou
Copy link
Member

Calinou commented Aug 7, 2022

Any updates?

Same as above. We need a motivated contributor to do the work 🙂

@bnolan
Copy link

bnolan commented Aug 22, 2022

We (www.voxels.com) would be happy to create a bounty or sponsor a developer to get this working for ios so we can embed our godot 3.5 renderer into a swift ui app.

@clintonrocksmith
Copy link

Hello, has this issue been picked up? I've got many years of mobile development and thought I'd have a go at this.

@Calinou
Copy link
Member

Calinou commented Sep 21, 2022

Hello, has this issue been picked up? I've got many years of mobile development and thought I'd have a go at this.

No contributor has tried to tackle this yet. Feel free to give it a try 🙂

@bnolan
Copy link

bnolan commented Sep 22, 2022 via email

@ismyhc
Copy link

ismyhc commented Apr 27, 2023

Hi, has any progress been made on this?

Having the ability to embed a Godot game into SwiftUI would be an amazing feature.

Im willing to help finically support a bounty along with @bnolan on this.

@Calinou
Copy link
Member

Calinou commented Apr 27, 2023

Hi, has any progress been made on this?

No contributor has tried to tackle this yet. Feel free to give it a try 🙂

@esummers
Copy link

esummers commented Apr 27, 2023

This would likely be a starting point:
https://github.com/migueldeicaza/SwiftGodot

Since Godot can't be used as a library, it would need SwiftUI called from the Godot side.

@jbromberg
Copy link

jbromberg commented Oct 5, 2023

I'd be willing to provide significant financial support to anyone who wants to tackle this. It's currently a blocker for us in using Godot.

@migueldeicaza
Copy link

While I am happy to see folks point to SwiftGodot, that won’t really do much to reach the stated goal. It doesn’t do much to help you. And sadly neither would SwiftGodotKit, which is more of a “drive Godot from swift” and not the “make Godot render into a UIView I can control at will” or the more ambitious “make Godot render in these five views, each with their own thing”

@jbromberg
Copy link

Hey @bruvzg I see you've self-assigned this proposal. I'm sure you're extremely busy, was just wondering if there are any near term plans for implementing this.

@bruvzg bruvzg removed their assignment Oct 16, 2023
@bruvzg
Copy link
Member

bruvzg commented Oct 16, 2023

Hey @bruvzg I see you've self-assigned this proposal. I'm sure you're extremely busy, was just wondering if there are any near term plans for implementing this.

I'm not currently working on it. I have self-assigned when I was trying to implement Godot Editor support for iOS, but this requires a lot more changes (running multiple Godot instances in the one process in particular) than just an embeddable view.

@migueldeicaza
Copy link

I had just filed an issue for a tangentially related issue that touches on both @jbromberg request and @bruvzg 's comment:

#8151

@zxffffffff

This comment was marked as off-topic.

@Legoless
Copy link

Legoless commented Jan 11, 2024

Not sure how far you already are @migueldeicaza, but I had already implemented this for Unity, since we needed to go back and forth between Unity game and our native part of the app (we added Unity games in existing app that's been on the market 5+ years). We also wanted to run Unity in background (without sound) and run certain Unity C# scripts. That was made possible by taking control of Unity bootstrap code and making it render on a UIView instance that would be in background. Basically you can do anything with this UIView, add it to a custom controller, open half of a native UIView above, even use it with SwiftUI views (through UIHostingController of course). That helped us to get our Unity assets all downloaded in background (by common C# code). The only limitation remained, that only one instance of the view could be used on screen at the same time, same as here as mentioned in other threads because singletons are used. However in theory, if macOS can run multiple windows in same process, then iOS should be able as well.

So since the fiasco with Unity runtime fees, we're considering switching to Godot and this does seem like a limitation for us as well.

With some financial support, maybe I'd be interested in doing this for Godot as well. Doesn't look too complicated looking at platform export code and Godot view in Objective-C++ here: https://github.com/godotengine/godot/blob/master/platform/ios/godot_view.mm

However, I'm new to Godot and all and would likely need someone to guide me a bit to get started. By the looks of it, Godot cannot be exported as a .framework like Unity can, which is usually the easier way to include it as embedded view.

Is there any work being done here and is the interest still around?

@migueldeicaza
Copy link

There is already a patch developed that I believe is being upstream in the 4.3 window

@ducpt-bili
Copy link

Thank for all the hard work.
I just wonder if the feature embed ios Godot game to ios, make game and native app communicate is work? Really need this feature. If that already work please help me with the link to the docs or sample please. I can't find anything about it.

@migueldeicaza
Copy link

I don't think there are docs yet because as far as I can tell the patch has not been submitted yet.

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

No branches or pull requests