Open migueldeicaza opened 1 year ago
@migueldeicaza I've implemented similar support for using Godot as a view on Android, and running into similar limitations due to the fact that only one Godot instance can run per process.
One workaround I have considered (and working to prototype in Godot 4.3) is to leverage Godot 4.x multi-window support to achieve the scenario you described within the same process.
The difference with your proposal would be that each GodotView
would instead be backed by a Godot Window
instead of being backed by a full instance of Godot.
I'm not familiar with iOS, so here's a high level overview of how this would work on Android:
Surface
objectSurface
that's used by the engine for renderingSurface
instances, one for each Window
reported by the engine (so long as the Window
is not embedded)GodotView
through a single Godot project, which may facilitate development and maintenance (in my subjective opinion)Don't get me wrong, there's still value in being able to instantiate multiple Godot instances in a single process, and that should also help for code encapsulation, maintenance and testing; but this may not be a hard blocker for the scenario you're describing.
I'd love to have that change (sorry for the spam, but I'd be so hyped about that change. That way we could use Godot in mobile applications to enhance the user experience so much!)
I'd love to have that change (sorry for the spam, but I'd be so hyped about that change. That way we could use Godot in mobile applications to enhance the user experience so much!)
@hannojg Even with the current limitations in place, Godot is already useable in mobile applications. See https://docs.godotengine.org/en/latest/tutorials/platform/android/android_library.html for reference.
This is the approach used by the Tesla Android and iOS mobile apps.
Yes, I know, however it's too limited. I'd need to use it in a similar manner as @migueldeicaza . So some limitations are:
Describe the project you are working on
I work on the Swift bindings for Godot (SwiftGodot) and many of my users would like to use Godot and SwiftGodot in Apple platforms not just for running a full game, but to spice up existing apps with Godot content - and not just one bit of content, but independently developed parts of content.
I imagine that this is not limited to iOS, it just happens to be an active platform where this is quite common, but I imagine Windows, Linux and other people might want similar functionality
Describe the problem or limitation you are having in your project
Godot currently has a number of globals and singletons and is designed for the whole process to be at the service of one instance of a project (or, the editor, or the project manager).
What I would like is to wrap the entirety of Godot into a class that can be initialized multiple times with different
project.godot
to execute, and to host the resulting view in different places. So Godot could be treated like an image viewer, just like you can add SVG images to your UI, you could add a Godot View:For example, this should be possible on iOS, which embeds three different instances of Godot, each with their own top-level project.godot, and when the user taps on one of them, it transitions to a full-screen version of the game:
Describe the feature / enhancement and how it helps to overcome the problem or limitation
All the singletons in Godot and global variables would have to be part of a "GodotInstance" class.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The good news is that most globals in Godot are already singletons and are being accessed with a
Class::singleton
pattern, which helps as a good flag of what needs to be instance-ified.All the singletons would be moved into a
GodotInstance
class, and this class would need to be reachable from every point that is currently using the singletons.There will be some plumbing required to pass the context/closure in places that currently lack it, so every place that currently relies on a
Class::singleton
would instead have aGodotInstance
classIf this enhancement will not be used often, can it be worked around with a few lines of script?
No, this scenario needs some changes to the Godot Engine.
Is there a reason why this should be core and not an add-on in the asset library?
Godot's current structure is such that the instance is managed by the operating system, as a process.
This would allow multiple godot instances in one process, each with their own settings.
Other uses
Scenarios that could benefit from this have been discussed in the past: