Skip to content

Commit e2aaed1

Browse files
authored
Merge pull request #11845 from Calinou/add-game-embedding
Add a page on game embedding
2 parents 9bffb36 + eb59049 commit e2aaed1

File tree

7 files changed

+292
-4
lines changed

7 files changed

+292
-4
lines changed

getting_started/step_by_step/nodes_and_scenes.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,22 @@ The application should open in a new window and display the text "Hello World".
161161

162162
Close the window or press :kbd:`F8` (:kbd:`Cmd + .` on macOS) to quit the running scene.
163163

164+
.. seealso::
165+
166+
See :ref:`doc_game_embedding` for more information about the Game window that appears
167+
when running the project.
168+
164169
Setting the main scene
165170
----------------------
166171

167-
To run our test scene, we used the :button:`Run Current Scene` button. Another button
168-
next to it, :button:`Run Project`, allows you to set and run the project's
172+
To run our test scene, we used the :button:`Run Current Scene` button. Another button
173+
next to it, :button:`Run Project`, allows you to set and run the project's
169174
**main scene**. You can also press :kbd:`F5` (:kbd:`Cmd + B` on macOS) to do so.
170175

171176
.. image:: img/nodes_and_scenes_12_play_button.webp
172177

173-
.. note:: Running the project's *main scene* is distinct from running the
174-
*current scene*. If you encounter unexpected behavior, check
178+
.. note:: Running the project's *main scene* is distinct from running the
179+
*current scene*. If you encounter unexpected behavior, check
175180
to ensure you are running the correct scene.
176181

177182
A popup window appears and invites you to select the main scene.
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
.. _doc_game_embedding:
2+
3+
Game embedding
4+
==============
5+
6+
Godot supports optionally running the game in the editor itself. This is enabled by default.
7+
8+
.. note::
9+
10+
The game always runs in a separate process, no matter the embedding mode used.
11+
This means that if the game crashes, it will not crash the editor.
12+
13+
Configuring game embedding
14+
--------------------------
15+
16+
Game embedding can be in one of 3 states:
17+
18+
- **Floating window** *(default)*: The game runs in a separate window, with a
19+
Game bar at the top that allows you to adjust settings and select nodes in the
20+
embedded game. Clicking the :button:`Game` main screen button focuses the
21+
floating window.
22+
- **Main window:** The game runs in the editor, with a Game bar at the top that
23+
allows you to adjust settings and select nodes in the embedded game. Clicking
24+
the :button:`Game` main screen button switches to the tab with the running
25+
project.
26+
- **Disabled:** The game runs in a separate window, as if it was an exported project.
27+
The Game bar at the top is not present; selecting nodes in the embedded game is not possible.
28+
29+
To configure this functionality, click the Game main screen at the top of the editor:
30+
31+
.. figure:: img/game_embedding_main_screen.webp
32+
:align: center
33+
:alt: Accessing the Game embedding main screen
34+
35+
Accessing the Game embedding main screen
36+
37+
Once on the Game main screen, click the dropdown menu in the top-right corner of the Game bar:
38+
39+
.. figure:: img/game_embedding_mode_dropdown.webp
40+
:align: center
41+
:alt: Game embedding mode dropdown
42+
43+
Game embedding mode dropdown
44+
45+
Two options are available to configure the game embedding mode:
46+
47+
- **Embed Game on Next Play:** If enabled, game embedding is enabled and the
48+
Game bar is available for use on the running game.
49+
- **Make Window Floating on Next Play:** If enabled, the game runs in a floating window.
50+
If disabled, the game runs in the main editor window.
51+
52+
Embedded window sizing
53+
^^^^^^^^^^^^^^^^^^^^^^
54+
55+
As seen in the dropdown menu on the right of the Game bar, there are several
56+
choices available to configure the embedded window size behavior. This affects
57+
both the floating and main window embedding modes:
58+
59+
- **Fixed Size** *(default)*: Set the viewport size to a fixed resolution, as configured in the Project Settings.
60+
If both :ref:`display/window/size/window_width_override<class_ProjectSettings_property_display/window/size/window_width_override>`
61+
and :ref:`display/window/size/window_height_override<class_ProjectSettings_property_display/window/size/window_height_override>`
62+
are set above ``0``, this override is used instead.
63+
- **Keep Aspect Ratio:** The viewport size stretches to match the game window size,
64+
but always follows the aspect ratio defined by the ``width / height`` as configured
65+
in the Project Settings.
66+
- **Stretch to Fit**: The viewport size stretches to match the game window size,
67+
and may use an aspect ratio different than the one defined by the ``width / height``
68+
as configured in the Project Settings. This matches the behavior when game
69+
embedding is disabled.
70+
71+
These options have no effect when game embedding is disabled.
72+
73+
Features
74+
--------
75+
76+
When game embedding is enabled, several features can be adjusted while the
77+
project is running using the Game bar at the top.
78+
79+
.. figure:: img/game_embedding_game_bar.webp
80+
:align: center
81+
:alt: Game bar at the top of the embedded game window
82+
83+
Game bar at the top of the embedded game window
84+
85+
In order from left to right:
86+
87+
Pause (F9)
88+
^^^^^^^^^^
89+
90+
Pauses/resumes the game. When paused, the game will stop processing physics and
91+
idle frames, but it will still render and process input. This allows you to
92+
:ref:`select nodes in the scene <doc_game_embedding_interaction_mode>` and
93+
inspect their properties in the editor inspector while the game is running.
94+
95+
Frame advance (F10)
96+
^^^^^^^^^^^^^^^^^^^
97+
98+
Only available when the game is paused. Advances the game by one frame,
99+
allowing you to inspect the state of the game at a specific moment in time.
100+
This can be used to diagnose short-lived interactions (such as collisions)
101+
that are hard to inspect when the game is running at full speed.
102+
103+
Game speed
104+
^^^^^^^^^^
105+
106+
This option is a menu that can adjust the game speed. If the game sets
107+
:ref:`Engine.time_scale <class_Engine_property_time_scale>` at runtime, it will
108+
be multiplied by the value set here.
109+
110+
.. figure:: img/game_embedding_game_speed_dropdown.webp
111+
:align: center
112+
:alt: Game speed dropdown on the left of the Game bar
113+
114+
Game speed dropdown on the left of the Game bar
115+
116+
This can be used to view interactions in slow motion, or speed up the game
117+
significantly to test mechanics that normally take a long time to occur.
118+
119+
The reset button to the right of the dropdown resets the game speed to normal (1.0×).
120+
121+
.. tip::
122+
123+
When adjusting the game speed using this mechanism, the physics tick rate
124+
(determined by the
125+
:ref:`physics/common/physics_ticks_per_second <class_ProjectSettings_property_physics/common/physics_ticks_per_second>`
126+
project setting) is automatically multiplied by the game speed.
127+
This allows the game logic to run at a different speed without affecting the
128+
physics simulation. For example:
129+
130+
- If you set the game speed to 0.5, the physics tick rate is halved.
131+
- If you set the game speed to 4.0, the physics tick rate is quadrupled.
132+
133+
The :ref:`maximum number of physics steps per frame <class_ProjectSettings_property_physics/common/max_physics_steps_per_frame>`
134+
is also increased to match the new physics tick rate, but it will not
135+
decrease below the default value when running in slow motion.
136+
137+
.. _doc_game_embedding_interaction_mode:
138+
139+
Interaction mode
140+
^^^^^^^^^^^^^^^^
141+
142+
This controls the behavior when clicking or pressing keys while the embedded game window
143+
has focus.
144+
145+
- **Input** *(default)*: Allow game input as usual.
146+
- **2D:** Disable game input and allow selecting Node2Ds, Controls, and
147+
manipulating the 2D camera.
148+
- **3D:** Disable game input and allow selecting Node3Ds and manipulating the 3D camera.
149+
150+
Nodes that are selected in the 2D and 3D modes can be inspected in the editor's
151+
inspector, just like if they were selected in the editor. This allows you to
152+
inspect and modify properties of nodes in the running game.
153+
154+
.. warning::
155+
156+
Like in the Remote scene tree, changes made to the running game this way are
157+
not preserved when the game is stopped.
158+
159+
To make changes that are preserved after stopping the game, you need to select
160+
the nodes in the editor's Local scene tree and modify them from there while the game
161+
is running instead. Make sure :menu:`Debug > Synchronize Scene Changes` is enabled
162+
when doing this.
163+
164+
Select mode
165+
^^^^^^^^^^^
166+
167+
*Only effective if the interaction mode is 2D or 3D, not Input.*
168+
169+
When enabling this option, the "show list of selectable nodes at position
170+
clicked" mode is disabled. However, you can still perform this action in select
171+
mode by using :kbd:`Ctrl + Alt + Right mouse button` at the desired location.
172+
173+
Show list of selectable nodes at position clicked
174+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
175+
176+
*Only effective if the interaction mode is 2D or 3D, not Input.*
177+
178+
Like in the editor, this shows a list of selectable nodes at the position
179+
clicked. This is useful when multiple nodes are overlapping and you want to
180+
select a specific one. When enabling this option, select mode is disabled.
181+
182+
Toggle selection visibility
183+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
184+
185+
*Only effective if the interaction mode is 2D or 3D, not Input.*
186+
187+
By default, the selected node in 2D or 3D interaction mode is highlighted with
188+
an orange rectangle or box (like in the editor).
189+
190+
When this option is enabled, it appears as a closed eye icon. Future selections
191+
will not be highlighted in the game view, but are still selected for inspection
192+
in the inspector. This is useful to avoid visual clutter.
193+
194+
Selection advanced options
195+
^^^^^^^^^^^^^^^^^^^^^^^^^^
196+
197+
Two advanced options are available in the dropdown menu next to the select mode icons:
198+
199+
- **Don't Select Locked Nodes:** When enabled, nodes that are locked in the
200+
editor cannot be selected. This mimics editor behavior.
201+
- **Select Group over Children:** When enabled, grouped nodes are selected
202+
instead of their individual children. This mimics editor behavior.
203+
204+
Mute game audio
205+
^^^^^^^^^^^^^^^
206+
207+
This mutes game audio when enabled, without affecting the editor or other
208+
applications. This is particularly useful on macOS and Android, which do not
209+
come with a per-application volume slider out of the box.
210+
211+
Camera override
212+
^^^^^^^^^^^^^^^
213+
214+
When enabled, the camera stops following the game camera. You can then move the
215+
2D/3D camera freely by switching to the 2D/3D interaction mode and using the
216+
typical navigation controls:
217+
218+
- In the 2D interaction mode, use the middle mouse button (or
219+
:kbd:`Space + Left mouse button`) to pan around and the mouse wheel to zoom.
220+
- In the 3D interaction mode, hold the right mouse button and press :kbd:`W`,
221+
:kbd:`A`, :kbd:`S`, and :kbd:`D` to use freelook. Use the middle mouse button to
222+
orbit, :kbd:`Shift + Middle mouse button` to pan, and the mouse wheel to zoom.
223+
Additionally, you can use :kbd:`Ctrl + Minus`, :kbd:`Ctrl + Plus`, and :kbd:`Ctrl + 0`
224+
to control the field of view (relative to the game's own camera FOV).
225+
226+
This is useful to inspect parts of the scene that are not visible from the game
227+
camera's point of view, or to inspect the game camera itself. When the camera
228+
override is disabled, the camera will snap back to the game camera's point of
229+
view.
230+
231+
When disabling camera override, the overridden camera's position and rotation
232+
are not reset. This allows you to quickly toggle back and forth between the game
233+
camera and the overridden camera.
234+
235+
.. note::
236+
237+
If the camera override appears to be non-interactive, make sure to be in the
238+
2D or 3D interaction mode. The camera override will keep working while in
239+
the Input interaction mode, but you won't be able to move the overridden
240+
camera while in that mode (unless using the **Manipulate From Editors**
241+
camera override mode as described below).
242+
243+
When overriding the 2D/3D camera, the project's scripts are not aware of
244+
this camera override. Keep this in mind when inspecting properties that
245+
depend on the camera position, as they will account for the original camera
246+
position instead.
247+
248+
Camera override options
249+
^^^^^^^^^^^^^^^^^^^^^^^
250+
251+
- **Reset 2D/3D Camera:** Resets the 2D/3D camera to the position and rotation
252+
defined by the game. Note that the camera will still be frozen in place until
253+
you disable camera override.
254+
- **Manipulate In-Game** *(default)*: The camera override is controlled from the game window.
255+
This allows controlling the camera without needing to switch back to the editor.
256+
- **Manipulate From Editors:** The camera override is controlled from the editor
257+
window. This can be useful on multi-monitor setups where the editor can be
258+
displayed side-by-side with the running project. Also, when using this option,
259+
the camera override position can be remembered across project runs, since it
260+
will reuse the editor camera position directly when enabled.
261+
262+
.. note::
263+
264+
The camera override may appear less smooth while using the
265+
**Manipulate From Editors** camera override mode, as a result of using
266+
local network communication between the editor and the game to
267+
update the camera position.
268+
269+
Limitations
270+
-----------
271+
272+
Game embedding has a number of limitations to be aware of:
273+
274+
- In the Android editor, game embedding always uses a floating window.
275+
By default, the floating window is kept on top of the editor using Android's
276+
picture-in-picture functionality. This behavior can be disabled in the Game
277+
bar by unchecking :menu:`Keep on Top using PiP` in the menu on the right of
278+
the Game bar.
279+
- Window mode changes (e.g. fullscreen) are not supported when using game embedding.
280+
- When :menu:`Debug > Customize Run Instances...` is used to enable running with
281+
multiple instances, only the first instance will use game embedding. Other
282+
instances will spawn in their own windows, without the Game bar at the top.
2.82 KB
Loading
6.67 KB
Loading
2.05 KB
Loading
5.16 KB
Loading

tutorials/editor/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ in other sections where appropriate. For example, the :ref:`animation editor
2626
script_editor
2727
default_key_mapping
2828
customizing_editor
29+
game_embedding
2930

3031
XR editor
3132
---------

0 commit comments

Comments
 (0)