Skip to content

Surface orphan bits in @export_flags inspector after a flag is removed - #122436

Open
basteez wants to merge 1 commit into
godotengine:masterfrom
basteez:fix-export-flags-orphan-bit-72010-show-orphans
Open

Surface orphan bits in @export_flags inspector after a flag is removed#122436
basteez wants to merge 1 commit into
godotengine:masterfrom
basteez:fix-export-flags-orphan-bit-72010-show-orphans

Conversation

@basteez

@basteez basteez commented Aug 15, 2026

Copy link
Copy Markdown

Bugfix

Fixes #72010

Problem

When a flag is removed from an @export_flags declaration, any bit that was set for the removed flag stays in the stored value. EditorPropertyFlags only 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 4 after "Test 3" is removed.

Change

  • Accumulate all_flags_mask (the OR of every value that maps to a current flag) while building the checkboxes in setup().
  • In 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.
  • When every named flag has been removed, the orphan checkboxes are the only controls, so the property's label/focus reference is anchored to the first one.

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

  1. Attach a script with @export_flags("Test", "Test 2", "Test 3") var test_flags = 0 and print test_flags in _ready().
  2. Enable the last flag, then remove "Test 3" from the declaration.
  3. Before this change the removed flag's bit is invisible and still prints; with this change it appears as a "Bit 2 (unknown flag)" checkbox that can be unticked to clear it.

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.

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
basteez requested a review from a team as a code owner August 15, 2026 10:57
@basteez
basteez marked this pull request as draft August 15, 2026 11:00
@basteez
basteez marked this pull request as ready for review August 15, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

removing a flag from an @export_flag remains ticked

1 participant