You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Useful in both a desktop-platform game project and a non-game editor app
Describe the problem or limitation you are having in your project
A very common set of settings to save in almost all mature Godot projects for desktop platforms will be to save user set (or last used) window mode (such a fullscreen/windowed) or in windowed mode the window size and position. This is not difficult, but it needs a fair number of lines of code, and you also need to catch changes (see #5884) and ensure you save them before the application quits (which can be a little tricky).
And then you need to implement reading and restoring these settings at launch to get the user back to the window mode they used last. Which can be straight-forward, but might collide with project settings since you can only do this after the engine launch has finished (see #6247), and you can't resize or scale the window before it's initially shown for the startup splash. And you can run into some weird edge-cases when restoring windows on multiple monitor setups.
In case of hiDPI scaling (see #7968) where you might want to resize and add content_scale_factor scaling to you windows based on the monitor scale factor, you can't do this until after the engine has launched. So the splash window will always be the wrong size on either normal or hiDPI monitors.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
To make this easier for everyone and solve these issues I'd propose adding a new bool project setting "Reuse window state between sessions", that when enabled saves the state of the window (window mode, size, position, content_scale, maybe more?) when the project quits and then reuses this data on startup when the window initially loads to correctly setup the window the same as it was when the user quit.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
First of all add this new setting Reuse window state between sessions, for example at the end of the "Size" section display/window/size/
If this setting is enabled, on engine shutdown, record the current main window mode, size, position, content_scale etc in a simple Dictionary and write this to a custom user://godot_window_state.data file (or somewhere else if appropriate)
If this setting is enabled, on engine startup, check for the user://godot_window_state.data file and if it exists read it and apply this window state information to the main window, overriding the Project settings window properties. In other words restoring the window to the same state it was when the user quit the application.
EDIT: It seems that something similar has been implemented now for the editor: godotengine/godot#76085 perhaps parts of this this could be reused more generally for all Godot projects?
If this enhancement will not be used often, can it be worked around with a few lines of script?
It can be worked around, and is probably already worked around in most Godot projects targeting desktop platforms. However, if it was implemented as part of the core it would make the system more reliable than these workarounds, and would mean that individual project wouldn't need to bother implementing this on their own for each project.
Is there a reason why this should be core and not an add-on in the asset library?
One technical reason is that I don't know if such add-ons would be able to read files and change the main window before the engine has started, as I'm guessing they are loaded later. But I might be wrong about that.
A stronger reason is that I think it's something virtually all desktop projects would benefit from, so it would be great if it was included in the core engine.
The text was updated successfully, but these errors were encountered:
You don't really need to catch changes, just save current settings in NOTIFICATION_WM_CLOSE_REQUEST
Yes, this is true if you can rely on always getting this notification on quit. I've had issues historically that if you quit using get_tree().quit() you do not get this notification, only when you're quit by closing the window or using a native OS quit menu item. But this is only tangentially related to this proposal, and perhaps that was based on some other issue? If the check and saving of the state was done on engine shutdown you're right this would not be an issue, as that would always be run as long as the game shut down normally.
Describe the project you are working on
Useful in both a desktop-platform game project and a non-game editor app
Describe the problem or limitation you are having in your project
A very common set of settings to save in almost all mature Godot projects for desktop platforms will be to save user set (or last used) window mode (such a fullscreen/windowed) or in windowed mode the window size and position. This is not difficult, but it needs a fair number of lines of code, and you also need to catch changes (see #5884) and ensure you save them before the application quits (which can be a little tricky).
And then you need to implement reading and restoring these settings at launch to get the user back to the window mode they used last. Which can be straight-forward, but might collide with project settings since you can only do this after the engine launch has finished (see #6247), and you can't resize or scale the window before it's initially shown for the startup splash. And you can run into some weird edge-cases when restoring windows on multiple monitor setups.
In case of hiDPI scaling (see #7968) where you might want to resize and add
content_scale_factor
scaling to you windows based on the monitor scale factor, you can't do this until after the engine has launched. So the splash window will always be the wrong size on either normal or hiDPI monitors.Describe the feature / enhancement and how it helps to overcome the problem or limitation
To make this easier for everyone and solve these issues I'd propose adding a new bool project setting "Reuse window state between sessions", that when enabled saves the state of the window (window mode, size, position, content_scale, maybe more?) when the project quits and then reuses this data on startup when the window initially loads to correctly setup the window the same as it was when the user quit.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Reuse window state between sessions
, for example at the end of the "Size" sectiondisplay/window/size/
user://godot_window_state.data
file (or somewhere else if appropriate)user://godot_window_state.data
file and if it exists read it and apply this window state information to the main window, overriding the Project settings window properties. In other words restoring the window to the same state it was when the user quit the application.EDIT: It seems that something similar has been implemented now for the editor: godotengine/godot#76085 perhaps parts of this this could be reused more generally for all Godot projects?
If this enhancement will not be used often, can it be worked around with a few lines of script?
It can be worked around, and is probably already worked around in most Godot projects targeting desktop platforms. However, if it was implemented as part of the core it would make the system more reliable than these workarounds, and would mean that individual project wouldn't need to bother implementing this on their own for each project.
Is there a reason why this should be core and not an add-on in the asset library?
One technical reason is that I don't know if such add-ons would be able to read files and change the main window before the engine has started, as I'm guessing they are loaded later. But I might be wrong about that.
A stronger reason is that I think it's something virtually all desktop projects would benefit from, so it would be great if it was included in the core engine.
The text was updated successfully, but these errors were encountered: