I’m trying to write play mode tests for my ui elements, but I when I load a UI document, rootVisualElement is null:
[Test]
public void CanSerializeComponentElements()
{
var puzzle = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/UI/Prefabs/TestDocument.prefab");
var root = puzzle.GetComponent<UIDocument>().rootVisualElement;
Assert.IsNotNull(root); // fails
}
The prefab as a UIDocument component with a Uxml visual tree asset assigned to it. How do I initialize this document?