Search Issue Tracker
By Design
By Design in 2023.2.X
Votes
0
Found in
2023.2.0b3
Issue ID
UUM-47682
Regression
Yes
UIDocument's rootVisualElement recreated after MonoBehaviour.Start() when UIBuilder is opened
The rootVisualElement of a UIDocument component is recreated after MonoBehaviour.Start() is invoked.
The problem is that MonoBehaviours that uses the content of this UIDocument 's rootVisualElement are left with references to the old rootVisualElement.
Steps:
1. Create a Scene
2. Add a new UIDocument using "Assets/UI Toolkit/UI Document" menu item
3. Set the source asset of the UIDocument to an valid uxml asset with a button.
4. Create a MonoBehaviour and add it to the UIDocument game object.
5. In Start() of the MonoBehaviour, connect an action to the click event of the button of the UIDocument.
void Start()
{
getComponent<UIDocument>().rootVisualElement.Q<Button>().clicked += myAction;
}
6. Open the UI Builder
7. Start play mode
8. Verify that clicking on the button triggers your action.
Actual outcome:
The action is not executed because the whole UI Document's content has been recreated with a new rootVisualElement after Start() was invoked (seems to be caused by due to live update).
Expected outcome:
Not sure,
1) Maybe the content should never been recreated
2) or there should be at least a notification when the content is recreated but this lead to a different way to access with UIDocument from MonoBehaviours.
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
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
Resolution Note:
This is indeed a non-ideal design at the moment, however, it is still "by design". Using Start() to created UI Toolkit is not supported when also using UI Builder's Live Reload feature. Always create UI in OnEnable().
Resolution Note (2023.2.X):
This is indeed a non-ideal design at the moment, however, it is still "by design". Using Start() to created UI Toolkit is not supported when also using UI Builder's Live Reload feature. Always create UI in OnEnable().