How delete options from the dropdown gui withscript?

Heyho, I mage a GUI where u got some buttons if u hit one a list of gameobjects are loaded from resources and a dropdown menu is filled with option. Now I got to my problem. How Can I delete the dorpown.options which are curently created ? I tried .ClearList but this doesnt work any Ideas?

Here is a lil bit of my code which is relevant to this problem:

       public void LoadShopsSpec()
     {
   
         _dropdown.gameObject.SetActive(true);
         SpawnPlaceHouse = ShopSpec;
         string ShopsSpec = "ShopsSpec";
         InitGui(ShopsSpec);
     }
     public void LoadShopsCorner()
     {
         _dropdown.gameObject.SetActive(true);
         SpawnPlaceHouse = ShopCor;
         string ShopsCorner = "ShopsCorner";
         InitGui(ShopsCorner);
     }
   void InitGui(string BuildingType)
     {
      if(_buildings != null)  Array.Clear(_buildings, 0, _buildings.Length);
         _buildings = Resources.LoadAll<GameObject>(BuildingType);
   
         foreach (GameObject buil in _buildings)
         {
             GameObject buils = buil.gameObject;
             string building_ = buil.name;
             _buildingsname.Add(building_);
          
         }
         foreach (string c in _buildingsname)
         {
            
             _dropdown.options.Add(new Dropdown.OptionData() { text = c });
            
         }
     }

push would be fine if someone could help :stuck_out_tongue:

You may want to use .options.Clear()

Then you need to refresh, otherwise you will continue to see what is on the label of the dropdown. To refresh simply change the value twice:

.value = 1;

.value = 0;

You may want to check questions on UnityAnswers, to learn how things works, if the manual does not have the answers.

Also a nice cleanup on the post would be appreciated; it is a bit hard to follow the IM-style that you use; here there is no limit on the characters that you can type :slight_smile:

Today (11-2017) .ClearOptions(); does the trick: https://docs.unity3d.com/ScriptReference/UI.Dropdown.ClearOptions.html

1 Like