Hello everyone. I am trying to make a form in UI in Unity where I want to put two Dropdowns (Countries and Cities). The problem is that when selecting the country, everything is ok, but when trying to select the cities that belong to the country, Unity is blocked until it loads, 1-4 minutes. The cities to choose from are filtered based on the selected country. As you all know, dropdowns instantiate their options through a template. The problem comes from the large number of options that must be instantiated depending on the number of cities. An extreme case is the United States of America, it has around 20,000 cities, it is unmanageable. Does anyone know of any trick or method to be able to display this data in this Dropdown format or similar?
The typical solution to this problem comes in the form of paginating or otherwise retrieving only a small subset of your results as needed. Your dropdown can only display what, 20 elements at a time? There’s no reason to populate the list with 20,000 results all at once. You basically just fetch the first 20 or 50 or whatever you need and show those. Then as the user scrolls down, you can fetch more data as needed.
I haven’t done this in Unity but when I used to work on Android applications we had something called RecyclerView which would automatically reuse the same ~20 or so UI row elements in the list. So as you scroll down, the cells that are scrolled out of view are hidden, repopulated for a new result, and moved to the bottom of the list as necessary. This ensures that there are never more rows in memory than what is required to display to the user.
It looks like some people have deigned to bring similar functionality to Unity: GitHub - framg/RecyclerView-for-Unity: Recyclerview for unity