-
-
Notifications
You must be signed in to change notification settings - Fork 97
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 'tracker' string to .tscn files (for preventing data loss in tool scenes) #2365
Comments
The linked issues are related to the fact that what is currently running gets ungracefully disconnected from the scripts. The problem is not so much data loss, after all you kind of want it to happen, because scripts and scenes may have changed dramatically and may not map to the previous instance. The problem is mostly about how it happens ungracefully. So I am not sure how this proposal would address that situation. |
The way I use But by default, all the changes you made just get reverted when you run the scene. In the video, I save the data by toggling an As the video shows, this works perfectly for |
Hmm, I usually have to work with the opposite, because tool scripts actually change the scene and so on |
No, the |
Please see this minimal example project: Tool Save Load Example.zip
|
Is this resolved by godotengine/godot#50676 ? |
@Error7Studios Since 4.0 alpha 9, tool scripts should no longer reset their variables. Can you check if your problem is maybe resolved? |
--- solved --- --- Edit --- Example project: |
@Error7Studios seems like unrelated issues, make a bug report instead |
Issue is resolved in 4.0 Alpha 9. Thanks! |
Describe the project you are working on
Godot RPG Framework
Describe the problem or limitation you are having in your project
The framework I'm making uses tool scripts everywhere, and tool scripts reset their data on reload.
See #1012, #1659
This only happens under specific circumstances, as described in this comment.
My current workaround for this is to have a
save_data()
function which writes all of a node's property values to a file, and aload_data()
function which updates all the properties of the node using that file data.This saves/updates all variables in
get_script_property_list
.(See this example video where I show
tool
node property saving/loading in action.)This works, but there are a few problems with it.
save_data()
on all of the tool nodes before they reload, or any changes will be lost.load_data()
for each of these nodes at the top of their_ready()
func, so the in-game values match the in-editor values.load_data()
using an export var whenever the scene is re-opened in the editor to restore the saved state.4a. The node's
instance id
changes on every reload, so it can't be used as a dictionary key.4b. Using the node's
name
orpath
as a dictionary key won't work, because they can change between save and reload.(Also, multiple nodes can have the same
name
.).tscn
file doesn't assign any unique identifiers to child nodes that could be used to track them between save and reload if theirname
orpath
is changed.Describe the feature / enhancement and how it helps to overcome the problem or limitation
I propose that whenever a node is created or instanced into a scene, the
.tscn
file for that scene's root node assign each of these children a unique identifier, as mentioned in point5
above.This identifier should be a long string of randomly generated characters.
It should be long enough that it would be virtually impossible to generate the same one twice.
The string can then be added into the
.tscn
file, under each child node's section like this:[tracker= "y4r#t7jXJb5chf^Q#Lj2Pi$BN6QeoE3opZQMEBXV!8Etr&HmdAR77DMNKs$EQn23Xp1&Uh@8Hp8SC3j6^UCXt3^dUt&1E3pE3h"]
By doing so, it would be possible to have a single save file containing a dictionary of all nodes properties in the scene, using the
tracker
strings as keys.If the save file could be updated every time the current scene is saved, that would be ideal, because the user wouldn't have to remember to call
save_data()
manually.Also, when a
tool
script runs its_ready()
func, it should automatically callload_data()
.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
(See above)
If this enhancement will not be used often, can it be worked around with a few lines of script?
No. Also it would require remembering to put function calls in every tool script, and remembering to manually call
save_data()
every time a change is made.Is there a reason why this should be core and not an add-on in the asset library?
This would have to be built in, because it would require adding a new
tracker
section in every.tscn
file.It would also require automatically calling
save_data()
whenever a scene is saved, andload_data()
in the_ready()
func for tool scripts.Minimal Example Project
Tool Save Load Example.zip
Steps:
Main
scene, and click on theToolScene
child node.ToolScene
export varTexture Index
to eitherGoblin
orHuman
.Label
andTextureRect
properties will not match the editor._ready()
func inToolScene.gd
, and uncomment the line,G.load_property_dict_file(self, SAVE_FILE_PATH)
The text was updated successfully, but these errors were encountered: