Skip to content

Add "Game" editor for better runtime debugging#97257

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
YeldhamDev:guess_godot_is_unity_after_all
Nov 1, 2024
Merged

Add "Game" editor for better runtime debugging#97257
Repiteo merged 1 commit intogodotengine:masterfrom
YeldhamDev:guess_godot_is_unity_after_all

Conversation

@YeldhamDev
Copy link
Copy Markdown
Member

@YeldhamDev YeldhamDev commented Sep 20, 2024

Implements several aspects of godotengine/godot-proposals#7213.

2024-09-20.19-19-42.mp4

Features Implemented

  • Selection of 2D/3D nodes at runtime when the game is suspended (see below), this includes anything that has collisions or some sort of visual representation. When a node is selected, a selection box will appear around it and it will be opened in the inspector.
  • Suspend mode. This is a middle ground between in-game pausing and the editor's break feature. When this mode is enabled, it allows node selection, and frame skipping.
  • Next frame. This allows the game to run one frame at the time when the it's suspended.
  • 2D/3D camera override. The camera manipulation can come from within the game, or the 2D and 3D editors.

Things Missing

  • Window embedding. This requires low-level OS-specific code, that's above my league.

Limitations

  • For now, selection only works in the root window. This is not a hard limitation, and selection in subwindows could be implemented as well.
  • No editor theming for the selection boxes and popup list, as well as no shortcut redefinition for camera controls, since we can't access those values at runtime. A possible workaround would be to pass those settings via the debugger.

Compatibility Break

  • A minor one is unavoidable to add this new editor to the feature profile.

Sponsored By: 🐺 Lone Wolf Technology / 🍀 W4 Games.

@YeldhamDev YeldhamDev added this to the 4.x milestone Sep 20, 2024
@YeldhamDev YeldhamDev requested review from a team as code owners September 20, 2024 22:34
@YeldhamDev YeldhamDev marked this pull request as draft September 20, 2024 23:05
@YeldhamDev YeldhamDev force-pushed the guess_godot_is_unity_after_all branch 2 times, most recently from f27cb5e to aa9fd47 Compare September 21, 2024 03:01
@YeldhamDev YeldhamDev force-pushed the guess_godot_is_unity_after_all branch from aa9fd47 to baedb41 Compare September 21, 2024 03:15
@JoNax97
Copy link
Copy Markdown
Contributor

JoNax97 commented Sep 21, 2024

This is excellent!

One small detail I think would be neat is to freeze the time parameter in shaders while the game is suspended, so that the effects don't continue animating and the 'next frame' button allows for shader debugging

@YeldhamDev YeldhamDev force-pushed the guess_godot_is_unity_after_all branch from baedb41 to 1581db4 Compare September 21, 2024 14:03
@YeldhamDev
Copy link
Copy Markdown
Member Author

@JoNax97 Done!

@RobProductions
Copy link
Copy Markdown
Contributor

Finally, this is incredible work and I'm really excited to see this merged! Thank you so much! A few questions:

  1. I can't tell from the video but does the click selection also work to highlight the tree item in the "remote" tab? I see it selects the remote note in the inspector which is great but it would also be cool to quickly navigate a complex hierarchy by selecting stuff, which would quickly unfold the parent items. I believe I've seen a plugin do this recently.
  2. Would it possible to separate the "suspend" mode from the click selection so that users can click on things while the game is not paused? Like maybe with a separate toggle to activate a selection mode instead of being tied to suspend? I think this was something mentioned in the original proposal with the "selection mode", and being able to click on (and eventually edit I presume) nodes while the game is running could save a lot of time for realtime tech demos (like cloth physics demos as an example) that would otherwise have to implement their own selection tools. I'm also imagining a debug camera being the next step here and that might fit better in a selection mode rather than suspend mode because you could take a look at something more closely while its in motion/changing instead of having to unpause and repause and find that exact spot again.
  3. Finally, and this may be a big ask, but is there potential for users to extend the functionality of these new runtime tools with custom code? For example, if there was never a PR for changing camera in pause mode, a user might want to code their own camera system that hooks into the new suspend code. But since I noticed that the can_process method now checks for suspend status, no user code can be run while the game is paused. This makes sense as a quick way to halt scripts but it would be neat to allow some way to customize how the tools work, though I'm not exactly sure how. On that note, it would also be great to get a signal for suspend and unsuspend to coincide with the notifications, that way at least user code can run when the mode starts and stops :)

I don't think all of that necessarily needs to go in this PR but just curious about the future of this feature. Regardless, I really appreciate what you have so far!

@YeldhamDev
Copy link
Copy Markdown
Member Author

@RobProductions

  1. Yes! And clicking an item in the remote tree also highlights the node in the game as well.
  2. Internally we settled to make selection only available when suspended, as the inputs of clicking around would clash with in-game code.
  3. This sort of stuff would need to have its own proposal opened for discussion, as this is beyond the scope of this PR.

@m4gr3d
Copy link
Copy Markdown
Contributor

m4gr3d commented Sep 22, 2024

Great work!

I'm curious how this would behave for an XR project.. would it be possible to disable the Game tab for an XR project but keep the functionality shown in the video?
cc @BastiaanOlij

Also I'm curious if this would work with the Android editor. Have you tested this PR with the Android editor?

@RykoTheDev

This comment was marked as off-topic.

@Kathenae

This comment was marked as off-topic.

@Faless
Copy link
Copy Markdown
Collaborator

Faless commented Sep 22, 2024

3. Finally, and this may be a big ask, but is there potential for users to extend the functionality of these new runtime tools with custom code? For example, if there was never a PR for changing camera in pause mode, a user might want to code their own camera system that hooks into the new suspend code. But since I noticed that the can_process method now checks for suspend status, no user code can be run while the game is paused.

@RobProductions I haven't checked the code yet, but like this PR is doing, you can have your own code evaluated outside of process (even during debug breaks), by registering a capture in EngineDebugger and implementing a EditorDebuggerPlugin to communicate with it.

@adevinwild

This comment was marked as off-topic.

@YeldhamDev YeldhamDev force-pushed the guess_godot_is_unity_after_all branch from 1581db4 to 39a0360 Compare September 22, 2024 13:48
@Chaosus
Copy link
Copy Markdown
Member

Chaosus commented Sep 22, 2024

Nice work, I would like to see more controls for the interacted objects (in Unity you can move, rotate, scale in this mode?), maybe some new buttons needs to be introduced for this.

@KoBeWi
Copy link
Copy Markdown
Member

KoBeWi commented Sep 22, 2024

  • Sometimes the suspend button is stuck disabled:
fbq8107lZ3.mp4

This happens after running the project a couple of times and requires restarting editor to fix.

EDIT:
Seems to happen when you F8 to close the game. Looking at the implementation, maybe session counter is broken.

EDIT2:
Yep, F8 closes the session twice and makes the counter go negative permanently.

  • The selection popup appears at wrong position. Seems to be relative to "Game" position.
godot.windows.editor.dev.x86_64_BOfYg60Jin.mp4
  • It would be useful to have in-game shortcut for next frame. Clicking a button isn't always convenient.

@geowarin
Copy link
Copy Markdown
Contributor

geowarin commented Nov 11, 2024

It would be really handy if the game toolbar actions had configurable shortcuts (suspend in particular).

@JohnnyKeolot
Copy link
Copy Markdown

Game mode doesn't work for me on Windows 10, the game doesn't show up. Am I doing something wrong?
image

@Chaosus
Copy link
Copy Markdown
Member

Chaosus commented Nov 12, 2024

Game mode doesn't work for me on Windows 10, the game doesn't show up. Am I doing something wrong?

You need to press a play button (F5) to run a game. It's a bit counter-intuitive.

@JohnnyKeolot
Copy link
Copy Markdown

Game mode doesn't work for me on Windows 10, the game doesn't show up. Am I doing something wrong?

You need to press a play button (F5) to run a game. It's a bit counter-intuitive.

If I press play (F5), the window opens as usual. The window is not embedded in the editor

image

@Chaosus
Copy link
Copy Markdown
Member

Chaosus commented Nov 12, 2024

If I press play (F5), the window opens as usual. The window is not embedded in the editor

Yes, this is the current limitation. You can only interact with a non-embedded game window, at least until #99010 got merged.

@JohnnyKeolot
Copy link
Copy Markdown

If I press play (F5), the window opens as usual. The window is not embedded in the editor

Yes, this is the current limitation. You can only interact with a non-embedded game window, at least until #99010 got merged.

Thank you!

@Comdfsfsfas
Copy link
Copy Markdown

@YeldhamDev
If you want to embed the running window into the engine, you can refer to this plug-in:https://fabimakesgames.itch.io/embedgame

@Arnklit
Copy link
Copy Markdown
Contributor

Arnklit commented Nov 15, 2024

@Comdfsfsfas there is already a PR for embedding it. #99010

@Comdfsfsfas
Copy link
Copy Markdown

But I have always wanted to know, why not embed the runtime window into the 3D window, but open a new Game window. In fact, you can display the debugging tool on the 3D viewport during runtime (I think this is better)

@allenwp
Copy link
Copy Markdown
Contributor

allenwp commented Nov 17, 2024

But I have always wanted to know, why not embed the runtime window into the 3D window, but open a new Game window. In fact, you can display the debugging tool on the 3D viewport during runtime (I think this is better)

If you're meaning you'd like to have both the playable game and the embedded game workspace viewable and interactive at the same time, this proposal is a good place for discussion: godotengine/godot-proposals#11091

@vlcoo
Copy link
Copy Markdown

vlcoo commented Nov 20, 2024

I've tried my best on looking for a mention of this both in this PR and the related proposal, and I didn't find any discussion that answered my doubt, so:

I feel like the new "Suspend" button in the Game tab is pretty redundant (at least in the still dev version I tested) and clashes nastily with the existing Pause feature at the very top right. I couldn't see any difference in functionality, and some odd counterintuitive cases appeared like having the game Paused but not Suspended, or having it both Paused and Suspended. I still don't quite understand that. Is it going to be developed further, and I'm a bit too early perhaps?

image

@KoBeWi
Copy link
Copy Markdown
Member

KoBeWi commented Nov 21, 2024

You can't use picking when the app is stopped with the debugger's pause, because it's completely frozen.
The new Game pausing is implemented as forced pause at SceneTree level. It stops all processing, but you can still interact with the app.

@allenwp
Copy link
Copy Markdown
Contributor

allenwp commented Nov 21, 2024

I feel like the new "Suspend" button in the Game tab is pretty redundant (at least in the still dev version I tested) and clashes nastily with the existing Pause feature at the very top right.

I think there might be a usability issue with using the same icon for both pause and suspend, given they do different things.

One idea that comes to mind is something about a stopped/paused clock that gives the idea that we are pausing time in the game when it is suspended, rather than pausing all rendering and interactivity. Maybe a clock with a pause icon over top of it. Not sure if this idea can be turned into a good looking icon. Also not sure if it makes sense to anyone else.

Maybe someone else has an idea of what a unique suspend icon could be…

@Zireael07
Copy link
Copy Markdown
Contributor

I think there might be a usability issue with using the same icon for both pause and suspend, given they do different things.

Agreed.

@peerlessblue
Copy link
Copy Markdown

I feel like the new "Suspend" button in the Game tab is pretty redundant (at least in the still dev version I tested) and clashes nastily with the existing Pause feature at the very top right.

I think there might be a usability issue with using the same icon for both pause and suspend, given they do different things.

One idea that comes to mind is something about a stopped/paused clock that gives the idea that we are pausing time in the game when it is suspended, rather than pausing all rendering and interactivity. Maybe a clock with a pause icon over top of it. Not sure if this idea can be turned into a good looking icon. Also not sure if it makes sense to anyone else.

Maybe someone else has an idea of what a unique suspend icon could be…

Maybe a snowflake? If I understand the difference in functionality correctly….

@vlcoo
Copy link
Copy Markdown

vlcoo commented Nov 22, 2024

You can't use picking when the app is stopped with the debugger's pause

Ok thanks, I understand the justification now. A part of me still wishes that it was possible to pick nodes when Paused (so a Suspend isn't needed), but I'm getting way ahead of myself - maybe a different time.

Maybe a snowflake?

That being said, I really like the idea of giving the button a different icon, and a snowflake representing "freeze (the game)" feels clear enough to me. Just wanted to add that I believe a tooltip on the button describing the use of the feature would avoid confusions even more.

@chansen1029
Copy link
Copy Markdown

"Game embedding not available on your OS." - Is there any plans to support mac users? ( MacBook Pro M3 - Sequoia 15.3.1 )

@Arnklit
Copy link
Copy Markdown
Contributor

Arnklit commented Mar 11, 2025

"Game embedding not available on your OS." - Is there any plans to support mac users? ( MacBook Pro M3 - Sequoia 15.3.1 )

Embedding the window on MacOS is considerably more complicated than on Windows and Linux, which is why it wasn't included in 4.4. There is a proposal for it here: godotengine/godot-proposals#11453, but it will probably require someone with a good understanding of Apple rendering APIs to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Add a keyboard shortcut to pause and perform frame-by-frame stepping when running a project from the editor