-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Embed game process in editor #99010
Embed game process in editor #99010
Conversation
8aa3953
to
e6bdeae
Compare
e6bdeae
to
9b9207e
Compare
Add |
Is this a limitation? If not, you could embed multiple instances inside a TabContainer. EDIT: |
This comment was marked as resolved.
This comment was marked as resolved.
9b9207e
to
abeae2c
Compare
I added "embedded" to |
abeae2c
to
c34b874
Compare
Thanks for the amazing work @Hilderin, this complements the new Game tab very well! |
@akien-mga / @bruvzg OpenEmu does what you describe for macOS, as it spawns a child XPC process, and uses a remote layer (the Metal / Vulkan frame buffer), to display in the parent process, which is the most efficient. WebKit does this, by running subprocesses for the browser engine and displaying them all in a single, parent process. I might take a look at that, if no one else is. |
I’ve worked with IOSurface before and always wanted an excuse to do more XPC on macOS, so I’m also putting this on my todo and hope to get to contribute unless someone gets there before me :) |
I've been testing this feature (don't know if I have to report this on a new ticket, or here as is for this feature). I'm testing with dual-monitor. If I use the Embed Game Process, the settings configured in Editor Settings > Run > Window Placement are ignored (I have set the Screen Placement on Next Screen, but the embed game process appears on the last sceen, place and size). If I disable the embed game, the settings work as expected. Another issue is that once the embed game is disabled from the embed window I would suggest making the Game Embed state editor based than project based to add consinstency with the Editor Settings > Run settings and also adding the option to turn it on or off on the Editor Settings > Run > Window Placement as it seems more organic and intuitive to find those settings there. |
Is there a way to tell the editor to embed in GDScript? I'd like my tooling scenes to run in the editor while the main play to run its own window. I keep closing godot when I am intending to close the game (old habits die hard) |
|
This checks if the editor is embedded, but I wanted the script to tell the editor to run it embedded or not for a specific scene. |
If I understand correctly you want to be able via a I can see this could be useful in some situations. I suggest you create a proposal for this. |
It's possible if you find the embedding menu in the scene tree. |
#95392 should help with this 🙂 |
Not sure if its intended but you leave fullscreen while being in embedded game mode. In my case its unwanted. Fullscreen been activated to stay inside godot without being interrupted (by external pop ups for example). |
Not sure I understand exactly what you mean. You are walking about the Fullscreen mode of the editor right? I tested on my side and the editor stays in fullscreen while starting the game when embedded. Are you on Windows or Linux? Maybe with a bit more information and a video I could understand better. |
Yes im talking about the editor fullscreen - Im on linux (xfce - x11). The taskbar of my system only appears when im not in fullscreen and when i run an embedded project, it pops up. If i think about it, it could also caused by the fact, that the embedded project is a separated software instance, which opens up my taskbar. I dont have a screen recorder on this hardware to make a vid. |
I see, I'm not sure we could fix that with the way embedding works right now, but we could try. I suggest you create an issue with all this information. Thanks. |
Is there already an issue tracking the support of this great feature under (X)Wayland? My cursory search didn't turn up anything, but I might have missed it. I am on Fedora where the 'main' GNOME and KDE spins have removed X11 already and many of my students are running similar setups (or Arch with Hyprland, because that is 😎 now, I guess), so we cannot use it. Unfortunately, I'm not familiar with this area and can't offer a PR myself, but I would like to add a +1 to an existing or open a new issue to track the eventual inclusion of Wayland. |
@haslingerm It already works fine under XWayland with multiple windows (default configuration). I tested on Fedora 41 KDE on Wayland. If it doesn't work for you, please open a bug report. |
Oh! I totally misunderstood the 'floating window' option, somehow thinking they are mutually exclusive => PEBKAC, it works fine, sorry! |
This depends on #101774 to be merged first, but even with that in place, I don't know if it's technically feasible. Wayland is more strict with what apps can do with windowing compared to X11 when they are not compositors. |
Hi @vonflyhighace2! Yes, I'm planning to implement a Wayland-native approach to game embedding. I'm currently focusing on #101774 but note that this feature does not actually depend on it, as we don't have the same window handling capabilities as other display servers. I plan of using a "nested compositor" approach, basically turning Godot into an extremely stripped down Wayland compositor that displays the child process. |
Implements game embedding for Windows and Linux (X11 only) in the new Game Workspace: GitHub PR #97257
As suggested, this implementation places the running game window as a child of the editor and embeds it inside the Game Workspace. The running game remains a separate process, with all keys and inputs handled in a separate event loop to maintain performance even when embedded.
U7w7iZ8zil.mp4
New Options in the Game Workspace Toolbar
Embed game on Next Play: On/Off: Enables or disables embedding the next time the game is started. (Default: Enabled)
Make Game Workspace floating on Next Play: On/Off: When enabled, the Game Workspace opens in a floating window when the game starts. (Default: Enabled)
Keep the aspect ratio of the embedded game: On/Off: Maintains the aspect ratio of the game window in the Game Workspace while embedding is enabled. (Default: Enabled)
Important Information
Additional Features
Engine.is_embedded_in_editor()
method in GDScript/C#, which helps prevent errors when attempting to change unsupported window settings while embedded or for adjusting behavior based on whether embedding is active.OS.has_feature("embedded_in_editor")
.Making Your Game "Embedded-Compatible"
Handling Mouse Capture: Currently, no default keyboard shortcut exists to exit mouse capture mode when embedded, which can be inconvenient for games like the TPS Demo that hide the mouse cursor during gameplay. As a workaround, you can modify the game to toggle the mouse cursor on pressing the Escape key instead of returning to the menu. Here’s an example for
level.gd
:Preventing Fullscreen Errors: In the TPS Demo, errors occur when starting the game in fullscreen mode while embedded, as the
DisplayServer
does not allow window mode changes in embedded mode. You can prevent these errors using a simple check:Known Issues
Windows: If the user focuses on the embedded game and quickly clicks a button in the editor, the click may not register. This seems to be due to Windows taking too long to reactivate the editor window, causing the mouse-up event to be missed. Disabling
Unfocused Low Power Mode
while the game is embedded mitigates this issue but is not a perfect solution.Linux: X11 does not support moving windows outside screen bounds. If the editor window is moved outside the screen boundaries while embedding a game, the window is resized to prevent Linux from resetting its position to the screen edge. This limitation appears to be a known issue without a programmatic workaround.
Scene Previews Disabled: When the Game Workspace tab is active, scene previews are disabled because they appear under the embedded game. Since previews are standard controls rather than popups, this is a temporary workaround to prevent issues, though it disables scene previews. Addressing this in a future PR is recommended.
Game Process Recording: Tools like OBS Studio or Game Bar cannot record the embedded game by capturing the Godot Editor process. To record the game, you must capture the entire screen or a specific section of it. This limitation is expected given the separate processes for the editor and game.
Single Window Mode and Popups/Tooltips: When the game is embedded and the editor runs in single-window mode, all popups and tooltips are displayed beneath the embedded game process.
Embedded window can be moved with OS shortcuts: When the game is embedded some Windows or Linux shortcuts came be used to move the game window. I was not able to find a way to disable those shortcuts. On Windows we are talking about WindowKey+Shit+Right/Left and on Linux WindowKey+LeftMouseButton.
Testing