Allow pinning property values + Consistent property defaults #52233
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements godotengine/godot-proposals#2280.
Consistent property defaults
The first commit in this PR unifies what is considered to be the default value of a property, following the same precedence that the engine uses when instantiating an object. See the comments in the code for details. That means that Godot now has a single, universal idea of what is the default value of a property.
This (which is a follow up of #46270 + #51173) is important for the pinning (and, specifically, auto-pinning) to work reliably.
This first commit also does a lot of cleanup and refactor on the go, to remove duplicate code and make for that single source of truth goal in various aspects.
Allow pinning property values
The second commit is where the actual pinning magic happens. It implements the main idea described in the proposal, but taking some inspiration on one of the approaches suggested there, so the best of both worlds is present.
A key concept here is potential overriding. A property value is potentially overriding if the node has ancestors in the instance/inheritance chain, or if it has a script exporting that property. The latter means that this PR extends the pinnability mechanics to script export values so they also benefit from it. (Conversely, this means that the aforementioned cases where, without the protection brought by pinning, could be unexpectedly changed if some ancestor or the script exporting the variable changes are properly handled.)
Some highlights:
Only properties that are stored can be pinned. Two points derive from that:
Node
(and used in the cases of nodes that needed that). In this PR for master no cases have been found, since those properties are exposed in a different way, but the system is still there because it may be needed. In the version of this PR for 3.x a number of cases have found and been taken care of.Binary scene file format changes so properties can have the new
flags
field, which so far is onlt used for storing whether the value is pinned. Therefore, the binary scene format compatibility is broken.Text scene file format changes so the pinned flag can be stored, like this:
position = Vector2( 20, 0 ) [pinned]
. Godot versions prior to this PR will not be able to open scene text files that have pinned values.Some editor settings are introduced:
docks/property_editor/auto_pin_on_value_override
(defaults totrue
): If enabled, when you change a property value in the inspector in a potential overriding context the value is automatically pinned.docks/property_editor/auto_unpin_on_value_revert
(defaults totrue
): If enabled, reverting a value (by clicking on the circular reset arrow icon) also unpins it.docks/property_editor/show_pin_ui_only_if_override_possible
(defaults totrue
): If enabled, only properties in a potential overriding context display the pinning UI on hovering.WIth all those enabled by default, the pinning experience is something users won't almost ever have to worry about and the pinning UI only appears where relevant. That also provides the best experience possible to beginners, which won't see anything related to pinning until they start dealing with exported variables or instancing/inheritance. More advanced users are free to tweak the settings for finer control if that's what they want.
More images:
Version for 3.x submitted as #52234.