Surface orphan bits in @export_flags inspector after a flag is removed - #122436
Open
basteez wants to merge 1 commit into
Open
Surface orphan bits in @export_flags inspector after a flag is removed#122436basteez wants to merge 1 commit into
basteez wants to merge 1 commit into
Conversation
When a flag is removed from an @export_flags declaration, any bit that was set for the removed flag stayed in the stored value with no checkbox to represent it, so it could not be cleared from the inspector and kept printing at runtime. Track the mask of all valid flag values in setup() and, in update_property(), render an extra "Bit N (unknown flag)" checkbox for each stored bit that no longer maps to a current flag. These behave like regular flag checkboxes, so the orphaned bit can be unticked without losing data. Fixes godotengine#72010
basteez
marked this pull request as draft
August 15, 2026 11:00
basteez
marked this pull request as ready for review
August 15, 2026 11:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bugfix
Fixes #72010
Problem
When a flag is removed from an
@export_flagsdeclaration, any bit that was set for the removed flag stays in the stored value.EditorPropertyFlagsonly builds checkboxes for flags that still exist, so:update_property()only reflects bits that have a checkbox, so the orphaned bit never shows up in the inspector;_flag_toggled()reads the full stored value and only OR/ANDs the toggled bit, so the orphaned bit survives every toggle.The result is a bit that can't be cleared from the inspector and keeps being reported at runtime, e.g. the reproduction from the issue still printing
4after"Test 3"is removed.Change
all_flags_mask(the OR of every value that maps to a current flag) while building the checkboxes insetup().update_property(), surface every stored bit that maps to no current flag as an extra "Bit N (unknown flag)" checkbox, wired to the same_flag_toggled()path as regular flags. The user can untick it to clear the orphaned bit, and nothing is silently dropped.Values with no orphaned bits are unaffected — identical UI and identical emitted values.
Alternative considered
A smaller alternative is to simply mask out orphaned bits and emit the cleaned value on load. It was rejected here because it rewrites stored data on open (marking scenes/resources modified and dropping bits without the user's knowledge). Happy to switch to that approach if maintainers prefer the minimal patch.
How to verify
@export_flags("Test", "Test 2", "Test 3") var test_flags = 0and printtest_flagsin_ready()."Test 3"from the declaration.Known limitation (pre-existing, out of scope)
Partially-set multi-bit flags declared with an explicit value (e.g.
"Combo:6") can still leave an individual bit without UI representation. This is pre-existing behavior unrelated to the positional-flag case in #72010 and would be better addressed separately.