Search Issue Tracker

Fixed in 2021.2.X

Fixed in 2020.3.X

Votes

0

Found in

2019.4

2020.1

2020.2

2020.2.1f1

2021.1

2021.2

Issue ID

1304581

Regression

No

[UIElements] ArgumentException is thrown when the PropertyField is bind to the BuildTarget enum

UI Toolkit

-

How to reproduce:
1. Open the user's attached "TestUIElements.zip" project
2. Select the "TestObject" ScriptableObject in the Project window
3. Observe the Inspector window

Expected result: BuildTarget enum is displayed in the Inspector window
Actual result: BuildTarget enum is not displayed in the Inspector window and "ArgumentException: Default Index  is beyond the scope of possible value" error is thrown in the Console log

Reproducible with: 2019.4.18f1, 2020.1.17f1, 2020.2.2f1, 2021.1.0b2, 2021.2.0a1
Could not test with: 2018.4.30f1 (UIElements are not supported)

Notes:
- The issue is not reproducible with custom enums
- The issue is not reproducible with other built-in Unity enums

--

The problem is not coming from the fact there are multiple enum entries with the same value, it's from the fact that there is no enum value that equals zero. Since the enum member is initialized with zero (in the shared project "buildTarget") and said enum value does not exist for type BuildTarget, the PropertyField does not know what to select. To avoid problems, initialize the member with a valid value, for example:

[SerializeField]
private BuildTarget buildTarget = BuildTarget.NoTarget;

  1. Resolution Note (fix version 2021.2):

    UI Toolkit: Fixes 1304581: [UIElements] ArgumentException is thrown when the PropertyField is bind to the BuildTarget enum
    Popup/Dropdown (Enum-compatible) fields now gracefully handle unselected/invalid values.

    Fixed in: 2021.2.0a5

  2. Resolution Note (fix version 2020.3):

    Fixed in: 2020.3.25f1

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.