- Home /
Dropdown not showing after canvas set active
Unity 5.6.0f3
Place a Dropdown on a canvas (Screen Space - Overlay).
Run.
Dropdown works fine with default options.
Set canvas inactive.
Set canvas active.
Dropdown no longer shows. It is still there but I can not get it to show (except in Scene view by dragging it to the side of the canvas).
Any ideas?
Answer by xRoachx · Aug 17, 2018 at 09:24 AM
For those who still have the problem and want a simple workaround:
Create this simple script and add it to the DropDown GameObject:
public class DropDownFix : MonoBehaviour {
public string sortingLayer = "UI"; //Or what ever layer you want it to be
public void OnDropDownClicked() {
Transform droplist = transform.Find("Dropdown List");
if (droplist != null) {
droplist.GetComponent<Canvas>().sortingLayerName = sortingLayer;
}
}
}
And just add an Event Trigger to the dropDown Gameobject with an Pointer Click event calling the OnDropDownClicked() function.
Technically you don't really need the "droplist != null" but you never known.
Answer by Dhaval1992 · May 09, 2017 at 06:15 AM
Try to set the DropDown's anchor point as per your need and than check.
Anchor point makes no difference.
This problem occurs with a new scene, new canvas and new default dropdown - easy to reproduce. I can not understand why this has not been noticed before. Not only is the Dropdown List not visible but the Dropdown itself becomes frozen. (Only a problem with ScreenSpaceOverlay)
Hi, Just seen that glitch in unity 5.6 in my PC also. If we are activating/deactivating canvas with drop down list, than drop down list is not visible in the game view.
But i found one workaround on it: 1. Create a empty Game Object inside the Canvas. 2. Than put all the UI elements along with your Drop Down in this empty Game Object. 3. And do the active/deactivate function on that Game Object rather doing it on Canvas.
Try if it works for you also.
Thanks for this work around. Been scratching my head for days trying to figure out a solution
That works fine thanks but leads to other problems for me. I will wait a while to see if it gets fixed. I tried to report a bug but there seems to be a bug in the bug reporting app and it keeps failing!
What problem? Share it, if i can help you on it.
O$$anonymous$$ now. Bug reported (it was a windows problem).
Also experienced the same glitch(also on windows) do you have link to the bug submission?
Answer by GLonaa5baVCBOkT7 · Aug 08, 2017 at 07:28 PM
Not sure if this will fix your issue, but I was having a very similar issue. Unity adds a canvas component to the Dropdown template at run-time with Override Sorting checked and the sorting layer set to Default instead of UI. To fix I copied the values from the canvas component after unity created it and pasted it into a canvas component I added myself and then set the layer to UI (only difference I saw was Order in Layer was 30000). Alternatively you could uncheck override sorting but then you'd have to make sure nothing else clips it. No idea why it doesn't copy the sorting layer from the parent object at run-time.
Answer by ZzaAakK_Gaming · Aug 23, 2017 at 10:50 AM
Hi folks, I'm fairly new to Unity as well, and came across this post because I had the same issue. I found a way to solve the problem though. I noticed, in the editor, that the component 'Dropdown List' is never deleted, only deactivated with the rest of the object. As the canvas('Dropdown List') is created at runtime, all you have to do is make a call to delete the canvas as the dropdown box is shown again. The next time you click it the dropdown box will appear again.
DestroyObject (dropDownBox.GetComponentInChildren<Canvas> ().gameObject);
I hope this helps!
Excelent! Thanks ZzAak$$anonymous$$_Ga$$anonymous$$g
Answer by senkage · Oct 23, 2018 at 04:04 PM
I solved this issue by adding a Canvas component to the "Template" object and uncheck "Override Sorting", so that the dynamically generated "Dropdown List" will appear on the correct sorting layer.
Sorry let me correct myself: Ins$$anonymous$$d of unchecking "Override Sorting", you need to check "Override Sorting" and then select the right sorting layer (same one as your dropdown). This is because the actual Dropdown List object copies settings from "Template" object but by default it will set to Default sorting layer, causing it possibly goes behind other layers.
Your answer
Follow this Question
Related Questions
TextMeshPro dropdown default value change 0 Answers
Extending dropdown options to use something like ValueMembers? 0 Answers
Unable to reset dropdown value to -1 1 Answer
How to use options in the Dropdown menu UI? 2 Answers
4.6 combo/dropdown box 2 Answers