Search Issue Tracker
Won't Fix
Votes
0
Found in
6000.0.11f1
7000.0.0a1
Issue ID
UUM-75838
Regression
No
Instantiation fails and NullReferenceExceptions are thrown when instantiating a custom VisualElement using UxmlTraits
1. Open the attached “ReproProject”
2. Open the Addessables Groups window (Window → Asset Management → Addressables → Groups)
3. Select Build → New Build → Default Script Build
4. Select the “Play Mode Script” dropdown menu and choose “Use Existing Build”
5. Open the “InitScene” (Assets/Scenes/InitScene)
6. Enter Play mode
7. Click the “Spawn Blue” button and observe the Console
8. Click the “Spawn Red” button and observe the Console
Expected result: No errors are shown and both panels are instantiated
Actual result: The red panel fails to instantiate and error messages are shown
Reproducible in: 6000.0.11f1
Could not test with: 2021.3.40f1, 2022.3.38f1 (Missing UI Toolkit features)
Reproducible on: Windows 11, macOS 14.5 (Silicon)
Not reproducible on: No other environments tested
Notes:
* The issue does not reproduce if “Red” is replaced by “Red2” in “ScriptableObjects/Mapping”. “Red” uses UxmlTraits, "Red2" uses UxmlSerializedData
* Not reproducible in Player
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Sprite Importer Checkbox Label Truncated in UI (2D Template)
- Light theme icon is missing for Volume Component in the Inspector window
- Volume Profile effects are still showing and active in Game View when the Volume Profile is reset
- Shader Graph Tab Lacks Right Margin for Long Titles
- 2DLight component only renders when ShadowCaster2D components are within range in WebGL builds
Resolution Note:
The problem is due a combination of LazyLoadReference API functionality and the garbage collection that occurs after a scene is loaded. (1) When a ScriptableObject loaded through a LazyLoadReference, the MonoScript dependency is not loaded before the ScriptableObject is loaded. It assumes that the MonoScript is already loaded in memory. (2) Any unused assets are garbage collected occurs after a scene is loaded. When the scene is in a bundle, the MonoScript dependency is garbage collected. Because the MonoScript is unloaded, the ScriptableObject cannot be loaded correctly and results in the serialization read error.
A fix for this issue would be very high risk and the UxmlTraits API is obsolete in newer Unity versions. We recommend following the workarounds below.
Two workarounds are (1) use the new UxmlElementAttribute API which does not use LazyLoadReference (2) load the ScriptableObject from the bundle before performing the lazy load.