-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add a way for plugins to signal that they've made unsaved changes to a scene #2153
Comments
Most plugins that I make where I would hate for the data loss to happen deal with editing resources, not scenes. And plugins can also deal with non-Godot files when their core functionality is integration of some sort. So I would propose we do not make any assumptions as to what exactly is unsaved. Besides, this call ( As a more general solution which would also give greater benefits to plugins I'd propose two new methods instead:
An API like that can be used for the quit confirmation as well as for internal tracking of changed resources by plugins. Hits two birds with one stone, so I think it would be simply beautiful to do it this way. |
My alternate solution would be this: add a virtual method in EditorPlugin called |
Has anyone figured out a workaround / way to trick the editor into considering the scene changed? I'm open to workarounds ranging from inelegant to abominable. |
You can probably change a property of any node in the scene tree, wait for one frame, then change it back to its previous value. |
Commit no-op UndoRedo action. |
Same as @whogben , I'm trying to figure out a way to manually set a scene as dirty from editor plugin. If someone has a workaround, whatever it is, I'd be very grateful to read it. |
Any update on this? I would also greatly appreciate info on any workaround |
godotengine/godot#67503 will addres this. I'm going to modify it to allow per-scene unsaved status, but right now it's pending on another PR. I mentioned a workaround in my previous comment. |
The aforementioned PR was merged. Is _get_unsaved_status() enough to resolve this proposal? |
@KoBeWi from how I understood this solution, it shows the desired popup when closing a scene with changes, but it might have also been useful to be able to signal changes at any point in time, such that the asterisk (*) is displayed next to the scene name in the tab bar. |
You can mark the scene as dirty using EditorUndoRedoManager. But what if you don't use UndoRedo or use a custom history (e.g. ScriptEditor)? A generic The only reasonable solution I can think of is adding some |
We use the EditorUndoRedoManager in Terrain3D, and all of our edits show up in the history tab, but it doesn't mark the scene dirty and the scene can be closed without warning. And I don't see anything in the documentation about manually marking the scene dirty. Now that I've looked at this new function, I suppose it can help, but it seems like an unexpected implementation. I was expecting that the function would return an int or bool, not a string, and it's purpose would be to solely tell Godot if there are changes or not. Yes or no. Then Godot could warn the user with the standard, do you want to save/cancel/don't save? We already capture the pre_save notification so we can save our resource, we're just missing the scene dirty status. We don't need to ask the user any special question beyond the above. I suppose providing a list of changes to the user can be useful, and as long as Godot interprets a full string as yes and an empty string as no, that serves the same purpose. |
They probably show up as global changes instead of scene-specific. |
Please elaborate on that. I have the same issue, commiting an action never marked my scenes dirty. As to the function, in my opinion, the dirty flag not disappearing on undo is only a minor issue, and something that happens in many software products. It's preferable to ask once too often for saving, than to lose changes. |
Check the description of EditorUndoRedoManager, it explains how action context works. In short, your first operation in undo action should involve an object that belongs to a scene, i.e. a node or built-in resource (but not nested resource). If you can't provide object for operation, Scene actions show as white in History dock, global actions show with "accent color": Unlike scene actions, the global actions only make the project dirty (you can see * in the Godot's title bar). Here's example plugin that makes scene dirty. Put it in addons/ , enable, select Node2D and press D.
Dirty flag is irrelevant here.
That's how it works. |
Thank you for the clarification and the example, this has been confusing me, since I think I followed an unofficial tutorial. UndoRedo now also works as it should in my project. Otherwise, I cannot think of a situation that would require another implementation, so for me the proposal would be resolved with |
Currently, I tag my scene dirty by creating and commiting a no-op |
Seems like godotengine/godot#77750 added |
Describe the project you are working on
The Godot editor 🙂
Describe the problem or limitation you are having in your project
Now that the quit confirmation has been removed when there are no unsaved changes, we need to be extra sure that no data can be lost when closing the editor.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a property/method in an editor class to signal that unsaved changes have been made to a scene.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Some design questions remain:
EditorInterface.set_dirty(bool p_dirty)
method.EditorInterface.mark_as_dirty()
.If this enhancement will not be used often, can it be worked around with a few lines of script?
Not that I know of.
Is there a reason why this should be core and not an add-on in the asset library?
This is about preventing data loss, so it's essential to have in core.
The text was updated successfully, but these errors were encountered: