-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
base: master
Are you sure you want to change the base?
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
I tried to disable window moving on x11, but nothing seems to do the trick. Following the x11 documentation, I tried setting
I'm really not an expert on x11 and Linux, maybe someone else can help to find a fix to prevent the use to move the window with the Window key? |
It's possible to move embedded window to another screen with Windows+Shift+Right. |
There needs to be another hint those toggles only apply next time the project is run, then. Alternatively, they should not be toggleable while the project is running. |
Functionality-wise it's mostly fine now, I went over the implementation and it looks ok too (aside from the comments I left). One major concern is that the editor is frozen while the embedded proces is starting. It's even worse when you have multiple instances enabled, because the editor waits for all of them. Embedding is enabled by default, so this will result in worse user experience (although also makes the Game tab closer to Unity I guess).
"Vulkan voodoo magic" is available only on Vulkan. We need a fallback implementation for other renderers. |
@Calinou ask me to add the "Next", we just need a consensus on that.
We just need a consensus because at first it was in the toolbar but I was asked to place these options in a menu. |
8ae4182
to
b3d8ee3
Compare
I'll try to look tomorrow or the next day for these issues:
|
I've tested a 2D Platformer Demo (https://github.com/godotengine/godot-demo-projects/tree/4.2-31d1c0c/2d/platformer) and noticed that the embedded viewport is very small - is this intended? Also in TPS Demo it is impossible to press Escape to switch modes without quit to main menu? |
Yes, as integer scaling forces the viewport's scale to be an integer value. Since the window embedding doesn't increase the window size automatically to account for the GUI controls displayed around the game, this "downgrades" the viewport's scale to a lower value. We could have the window size increase automatically to account for its controls to avoid this issue, but it will require the screen to be large enough to work. |
After testing and trying to fix these issues, bad news, I don't think it's possible to fix these, or at least, I did not find a solution.
The problem comes from Windows, when parented, when a process stops the WndProc loop, the other process stops also. So when then game window starts, Godot freezes when loading the game, causing the editor to freeze also. The bigger the project, bigger the issue is apparent. I tried to postpone parenting but Windows really does not like it and causes issues where the child window can appear behind the editor on startup and not moving while the game is loading, etc...
I don't think it's possible to disable this shortcut on Windows from an application. One way to maybe mitigate this issue similar to moving the window with Window+Shift+MouseLeftClick on Linux could be to check the game window position and relocate it every second or something from the editor. I'm not sure this is worth it. |
Check the PR description in the "Making Your Game "Embedded-Compatible" section. I guess the TPS demo should be upgraded to implement the modifications. |
What's your screen resolution? I guess you started the game embed in the editor and not in the floating window? In this mode, there's no way to actually resize the window by code because it's based on the size of the Game Workspace panel inside the editor. Also, you seems to a old version of this PR based on the options I see in the toolbar. I suggest you try in the "Make Game Workspace floating on Play" option and try to resize the window. In this mode, are you able to resize the game window on make the game bigger? |
b3d8ee3
to
8eba66c
Compare
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 Play: On/Off: Enables or disables embedding. (Default: Enabled)
Make Game Workspace floating on 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.
Testing