Let’s assume we have a simple test stylesheet:
The stylesheet is attached to the root of the visual tree. So far it works the way it should, all texts are red.
But if I dynamically add an element to the graph like this:
var template = Resources.Load<VisualTreeAsset>("MyTemplate");
var instance = template.CloneTree().ElementAt(0);
container.Add(instance);
The newly added element is not affected by the stylesheet of its parent VisualElement. It appears that I have to manually attach the stylesheet every time I use CloneTree():
instance.styleSheets.Add(styleSheet);
Am I doing anything wrong or is it a bug?