Hi all, i’m currently working on a project where I want to change a UXML file depending on the unit type that I select. So an Infantry unit should have a different UXMl from a tank unit and so on. I did some research and found this approach:
VisualTreeAsset additionalVisualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(infantryAbilitiesFilePath);
if (additionalVisualTree != null)
{
VisualElement targetElement = document.rootVisualElement.Q<VisualElement>("AbilityBar");
if (targetElement != null)
{
// Clone the additional UXML and add it to the target element
VisualElement additionalContent = additionalVisualTree.CloneTree();
targetElement.Add(additionalContent);
}
else
{
Debug.LogError("Target element not found: ");
}
}
Would that be a viable way to change a uxml at runtime or is there an alternative? Thank you so much