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

Add support for embedding game process in the Android Editor #102492

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented Feb 6, 2025

Follow up to #97257 and #99010, this PR implements game embedding for the Android editor.

Screen_Recording_20250206_095310.mp4

Due to differences in platform capabilities, the Android implementation uses a custom floating window, implemented using Android views, which replaces the Game workspace view seen on other platforms; i.e: when embedded, the game view on Android is always floating.
The implementation also leverages Android picture-in-picture support (which was added in #95700) to allow the game view to remain on top (when enabled) while users interact with the editor.

Screen_Recording_20250206_095758.mp4

Note:

  • The PR looks big, but most of the changes are in the Android editor module, so there is little risk to the Godot Android core
    • The majority of the changes in the editor module are additions of media assets to recreate the look of the game view
  • The run/window_placement/play_window_pip_mode editor setting has been removed, instead PiP can be explicitly triggered when running in non-embedded mode, or is implicitly used in embedded mode when Keep on Top using PiP is enabled.
Screen_Recording_20250206_100359.mp4

Things missing

  • Ability to drag and resize the floating game view

Limitations

  • Embedded game mode is disabled for the XR Editor, support will be added in 4.5

Closes godotengine/godot-proposals#10884

Bugsquad edit, closes: godotengine/godot-proposals#11309

@AThousandShips AThousandShips added this to the 4.x milestone Feb 6, 2025
@m4gr3d m4gr3d modified the milestones: 4.x, 4.4 Feb 6, 2025
@m4gr3d m4gr3d force-pushed the android_editor_support_game_tab branch 2 times, most recently from 130555a to 4135461 Compare February 6, 2025 17:48
@m4gr3d m4gr3d marked this pull request as ready for review February 6, 2025 18:01
@m4gr3d m4gr3d requested review from a team as code owners February 6, 2025 18:01
@m4gr3d m4gr3d force-pushed the android_editor_support_game_tab branch 3 times, most recently from f8b5412 to 9b5f5a8 Compare February 6, 2025 18:28
@syntaxerror247
Copy link
Member

syntaxerror247 commented Feb 6, 2025

I haven't reviewed the code or tested this new mode yet. However, based on the screen recording you shared, it looks like the top toolbar remains visible even when embedded mode is turned off ( while running in split-screen). I think, it would be better to disable or hide the toolbar when embedded mode is off, It takes unnecessary space.

This is also inconsistent with the desktop editor, where the toolbar is disabled, and its options like camera override isn't available if embedded mode is disabled.

@dsnopek
Copy link
Contributor

dsnopek commented Feb 6, 2025

I haven't reviewed the code or tested this new mode yet. However, based on the screen recording you shared, it looks like the top toolbar remains visible even when embedded mode is turned off ( while running in split-screen). I think, it would be better to disable or hide the toolbar when embedded mode is off, I takes unnecessary space.

I have been testing this, and I can confirm that this is indeed the case: even with embedding disabled, the toolbar still appears. I agree that it shouldn't be there in this case.

UPDATE: Or, actually, then how would you change whether to embed on play or not? Because the settings for that are in the toolbar under the three vertical dots. Having those settings there is kind of awkward, because you have to actually start playing the game before you can configure how you want to play the game.

@syntaxerror247
Copy link
Member

UPDATE: Or, actually, then how would you change whether to embed on play or not? Because the settings for that are in the toolbar under the three vertical dots. Having those settings there is kind of awkward, because you have to actually start playing the game before you can configure how you want to play the game.

You can change it in EditorSettings run/window_placement/game_embed_mode.

Alternatively, if user opens the "game" tab it currently displays a message to run the game, Instead we can open the "Game" tab and let user to change the "Embed on play" setting?

@dsnopek
Copy link
Contributor

dsnopek commented Feb 6, 2025

A couple other things I noticed in my testing:

  • When the game disappears, it wasn't immediately clear to me that I had to press the "Game" tab to bring it back (since I pressed play to start the game, I never interacted with the "Game" tab). Some note about that when the game window minimizes could be helpful? Otherwise, my gut reaction was to look through the running Android apps (which it would be when not embedded) and, of course, it wasn't there.
  • It's also a little weird that the "Game" tab looks selected after I press it, but whatever the previous tab that was active is what will still be there, and will still work and everything. It'd be nice if it switched back to showing 2D or 3D or whatever as selected. (UPDATE: I guess it looks half-way like it's selected. The "2D" or whatever tab is blue, but the "Game" tab has the blue box around it, I think indicating that it's focused? Maybe it just need to relinquish focus after being pressed?)
  • My tablet doesn't support PiP, and so the checkbox doesn't do anything. Would it be possible to not have the checkbox if PiP isn't supported? (FYI, I also tested on my phone, which does support PiP and PiP seems to be working fine.)

@llama-nl
Copy link

llama-nl commented Feb 7, 2025

The visibility toggle button doesn't seem to work. But is can be change from inspector.
https://github.com/user-attachments/assets/2266c2d0-8855-46e9-954d-b598fa35da8d

Also could you make those button little smaller. Those buttons are taking lot of space.

And also please remove the the round corner and the bg shadow :/
Screenshot_20250207_075912

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Feb 7, 2025

The visibility toggle button doesn't seem to work. But is can be change from inspector.
https://github.com/user-attachments/assets/2266c2d0-8855-46e9-954d-b598fa35da8d

@llama-nl Seems like the visibility toggle is working in the recording you took.. Are you referring to something else?

@llama-nl
Copy link

llama-nl commented Feb 7, 2025

@llama-nl Seems like the visibility toggle is working in the recording you took.. Are you referring to something else?

@m4gr3d The toggle button is working. But the object/mesh it still visible no matter what:

az_recorder_20250207_111021.mp4

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Feb 7, 2025

@llama-nl Seems like the visibility toggle is working in the recording you took.. Are you referring to something else?

@m4gr3d The toggle button is working. But the object/mesh it still visible no matter what:

az_recorder_20250207_111021.mp4

@llama-nl that's the expected behavior; the visibility toggle is for the selection box around the selected object, not for the object itself.
Please refer to the feature description in #97257

@syntaxerror247
Copy link
Member

syntaxerror247 commented Feb 7, 2025

I am currently testing it on my phone, and Embed mode works great! However, I’m experiencing some UI issues, which are also visible in the screen recording you shared.

VID_20250207_110624.mp4

As you can see, when switching to fullscreen mode, it doesn’t fully expand and leaves a margin around the borders. Additionally, the status bar becomes visible, which I assume is unintended.

Another minor issue is that in PiP mode, a shadow appears around the borders. I’m not sure if this is intentional, but it seems out of place.

UPDATE: As you can see in video, when switching to PiP mode and then back to Embed mode, the rounded corners become sharp.

@syntaxerror247
Copy link
Member

VID_20250207_112827.mp4

Running the game with Embed mode disabled tries to launch it in split screen. While this works well for tablets, it’s not optimal for smartphones and is causing issues for me. It's currently not possible for me to run the game in fullscreen.

On a regular smartphone, it should default to fullscreen mode, just like it did previously, with a button to switch to PiP mode when needed.

@m4gr3d m4gr3d force-pushed the android_editor_support_game_tab branch 2 times, most recently from 76a4590 to 05aab5d Compare February 7, 2025 07:51
@llama-nl
Copy link

llama-nl commented Feb 7, 2025

Everything is as expected. Just I am unable to play game in side-by-side with editor mode with Game Embed Mode Enabled. Also the enable_game_menu_bar documentation is missing.

And a proposal: could you make the embed window center of the screen or a way to move the window.

@syntaxerror247
Copy link
Member

syntaxerror247 commented Feb 7, 2025

Everything is as expected. Just I am unable to play game in side-by-side with editor mode with Game Embed Mode Enabled.

That's the expected behavior. To run the game side-by-side with the editor, disable Embed Mode and ensure enable_game_menu_bar is enabled for all games (It's enabled by default). This will provide the same functionality.

And a proposal: could you make the embed window center of the screen or a way to move the window.

The ability to drag and resize the window is planned, but it requires additional work and will be added in a follow-up PR (most probably in 4.4.1).

@dsnopek
Copy link
Contributor

dsnopek commented Feb 7, 2025

@dsnopek FYI, this is what I get on my device when I run the adb shell pm list features|grep picture command:

feature:android.software.picture_in_picture

Ah, ok, I get that on both my phone and my tablet, even though my tablet seems unable to actually put the embedded window in PiP. So, I guess it must be some issue with my tablet.

However to address your feedback, I've added another editor setting to disable the game menu on the regular play window! Do note however that the game menu on Android also hosts the minimize, enter pip and close button for the regular window, so disabling it takes those away.

Hm. This option works and does technically solve the problem, but having it as an editor setting makes it hard to get to or notice that it's there.

My main issue with the menu bar is that it can mess up the scaling of the game by taking up that extra space.

For example, here is the 2D platformer demo on my phone without the menu bar:

Screenshot_20250207_091957

And here it is with the menu bar:

Screenshot_20250207_091935

Could we maybe include this setting (and perhaps some others) in a more accessible place? Like, maybe the "Game" tab could show this setting as well as the ones about embedding and PiP, rather than just popping up the window?

Or, maybe there could be some way to hide the menu bar, sliding it away like a drawer, or something like that? Then it's not a setting but just a way of interacting with it to hide/show it.

@m4gr3d
Copy link
Contributor Author

m4gr3d commented Feb 7, 2025

Or, maybe there could be some way to hide the menu bar, sliding it away like a drawer, or something like that? Then it's not a setting but just a way of interacting with it to hide/show it.

@dsnopek I can add a button to show / hide the menu bar. That would also allow to remove the run/window_placement/enable_game_menu_bar editor setting since the button would provide the behavior @syntaxerror247 and you were requesting.

@syntaxerror247
Copy link
Member

syntaxerror247 commented Feb 10, 2025

@m4gr3d I encountered another issue. When GameWindow is visible and you close the app to background and then open from recents screen it would only open Embedded Game activity, Editor would be hidden. It can be really confusing as even if you close the Embeded game, Editor window won't show until you open app from launcher again.

I think possible solution would be to override the onResume method in Embedded Game activity and create an intent to show Editor.

@m4gr3d m4gr3d force-pushed the android_editor_support_game_tab branch 2 times, most recently from 752cb3f to d6c667a Compare February 10, 2025 23:38
@m4gr3d m4gr3d force-pushed the android_editor_support_game_tab branch 3 times, most recently from c087451 to 5aae392 Compare February 11, 2025 05:29
@m4gr3d
Copy link
Contributor Author

m4gr3d commented Feb 11, 2025

@dsnopek @llama-nl @syntaxerror247 All of your feedback have been addressed! Can you give the latest version a try?

When GameWindow is visible and you close the app to background and then open from recents screen it would only open Embedded Game activity, Editor would be hidden.

@syntaxerror247 That issue should also be resolved in the latest version!

@syntaxerror247
Copy link
Member

syntaxerror247 commented Feb 11, 2025

Everything works great! 🎉

I've actually been testing and reviewing every change you pushed to make sure nothing slipped through, especially as we approach the end of beta.

EDIT: Forgot to mention, the code also looks solid!

Copy link
Member

@syntaxerror247 syntaxerror247 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spotted a bunch of missing . I don't mind, but @AThousandShips wouldn’t like it 😀

@llama-nl
Copy link

Wow, now everything is perfect. Really grate work

- Implement Android editor specific `EmbeddedGodotGame` to support embedding the game window in the Android editor
@m4gr3d m4gr3d force-pushed the android_editor_support_game_tab branch from 5aae392 to 7495a8a Compare February 11, 2025 10:20
@dsnopek
Copy link
Contributor

dsnopek commented Feb 11, 2025

I can add a button to show / hide the menu bar.

I just tested this, and it works great! Could we have it even when in embedded mode? Because then I really don't think I'd have a reason to not use embedded mode, especially if the menu bar started out hidden. Like 99% of the time, I don't think I'd want to use the buttons on the menu bar and just want to test the game, so it makes more sense to me to have it hidden and then show it, rather than the other way around. I know it's shown by default on other platforms, but on mobile screen space is more precious.

Anyway, that's not worth getting hung up on now. :-) I haven't reviewed the code very deeply, but overall this is working great in my testing!

@Repiteo Repiteo merged commit 427d808 into godotengine:master Feb 11, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Feb 11, 2025

Thanks!

@m4gr3d m4gr3d deleted the android_editor_support_game_tab branch February 11, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants