-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Keep property values when extending script #43081
Conversation
I rebased and improved the PR. Aside from extending script, the properties will now be kept when making the script unique or attaching a new one (regardless if it's the same script or a completely different one; properties with the same name will keep values). |
Not sure how can this be fixed in script if the script is replaced by a different one. This is editor issue, because the script is removed and a new one is added and only editor can keep track of the former variables. |
editor/editor_node.cpp
Outdated
@@ -5808,6 +5831,9 @@ void EditorNode::_bind_methods() { | |||
ClassDB::bind_method("_close_messages", &EditorNode::_close_messages); | |||
ClassDB::bind_method("_show_messages", &EditorNode::_show_messages); | |||
|
|||
ClassDB::bind_method("store_object_properties", &EditorNode::store_object_properties); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO This function should only be called if you have a script, so the intention is better. Otherwise you have to go to the function and see that it does nothing if it has a script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, the function is supposed to store available script properties. If there is no script, it just has no properties to store.
It makes the code much simpler. Otherwise I'd have to wrap each call and make it less readable.
Thanks! |
Cherry-picked for 3.6. |
Closes #37480
EDIT: Closes godotengine/godot-proposals#4415
This can also trigger when replacing a script for one node. Making it work only with script extending would make the code more complicated, because the editor doesn't really differentiate between extending and attaching. I don't think this is a big issue.I added 2 methods in EditorNode:
store_object_properties()
andapply_object_properties()
. The first one gets properties from the script instance and stores it in EditorNode, the second one applies it to the new instance, to the properties that have matching name and type. The intended usage is that you call these methods as part of a UndoRedo action that changes script and the exported values are carried to the new script.The values will be preserved when: