I heard that the UI toolkit is a good way matching UI with ECS. I want to spawn buildings (prefabs) from a button press. What's the best way to do this?
I have two examples but I assume there are better ones:
var system = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<UIButtonSystem>();
system.SpawnEntity();
//example2
var query = entityManager.CreateEntityQuery(typeof(BuildingEntitiesComponent));
var buildings = query.GetSingleton<BuildingEntitiesComponent>();
entityManager.Instantiate(buildings.house);```
This code is in the VisualElement class of the game screen.
Thanks for your help!