fix(enums): harden EnumValues key resolution and lookup#97
Merged
Conversation
- Re-resolve SerializedProperty by path instead of holding stale references in the EnumValue/EnumValues drawers, preventing ObjectDisposedException on list reorder/delete - Invalidate EnumValues<T>'s resolved-key cache via ISerializationCallbackReceiver after Inspector edits, and reset a key that fails to re-parse, fixing stale/mismatched Key crashes across enum type changes - Guard GetValue/Equals/GetEnumerator against unresolved or unconfigured enum types instead of throwing, and prioritize exact-key over partial "contains" matches for [Flags] lookups - Add StringExtensions.ToKebabCase for element naming, mark _enumType as Required, and document the EnumValues.uss layout overrides
…events - PropertyField only forwards UI-driven ChangeEvents from custom drawers, so a type picked via the TypeSelector window (a direct SerializedProperty write) never triggered UpdateValues and rows kept rendering the old enum - track _enumType with TrackPropertyValue in both EnumValues/EnumValue drawers; drop the hidden per-row _enumType PropertyField that existed only as an event source
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.
Summary
🐛 Bug fixes in
EnumValues<TValue>/EnumValue<TValue>Equals/GetValue(HasFlagonnullor on a different enum type)HasFlag; fall back gracefully instead of throwingEnumValues<TValue>now implementsISerializationCallbackReceiverand invalidates the cache on every Inspector editEnumValue.Initializekept a staleKeyfrom a previous enum type after a failed parseKeytonullon failed parse_enumTypethrew instead of falling back to the default value[Flags]lookup used first-match-in-order, so a plain flag entry could shadow a more specific composite entry (easy to trigger via "Populate Missing Enum Members", which appends members in ascending value order)GetValuenow prioritizes an exact-key match over a broader "contains" match🛠️ Editor drawer hardening
EnumValuePropertyDrawer/EnumValuesPropertyDrawernow re-resolveSerializedPropertyby path instead of holding references across closures — preventsObjectDisposedExceptionon list reorder/delete.✨ Misc
StringExtensions.ToKebabCase, used for a validVisualElementname instead of the nicified, space-containingdisplayName._enumTypeas[TypeSelector(Required = true)].EnumValues.uss.Notes for review
✅ All correctness fixes were reproduced and verified against the real bug (not just typechecked) by driving the actual Unity Editor via
unicli Eval:constructed
SerializedObject/SerializedPropertyscenarios that previously threw, confirmed the crash, applied the fix, then re-ran the same scenario to confirm it no longer throws.Linked issues
—