Was wondering if anybody can help me. I’ve got a Canvas which has its Render Mode set to World Space.
Within this canvas, I have a Dropdown (from the new UI tools).
The problem is, the content of this dropdown appears behind other elements in my scene. In the screenshot, you’ll see it appears behind the canvas’ background…
If I add other elements to the scene, such as a background - NOT in the canvas, but on a background sorting layer - the dropdown list appears behind that too…
Not sure what else to try… I’ve tried setting sorting layers but I can’t find a way to set the sorting layer of the dropdown list…
If I’m in Play mode, I can see the “Dropdown List” appear in the Hierarchy, and if I modify the sorting layer to my UI layer, the list shows up fine. But of course, I can’t save this during Play mode, and once I exit Playmode, I lost the ability to edit the Dropdown List.
The dropdown list appears behind the other elements because its canvas has the sorting layer set to default while my other elements are in another sorting layer. Can I set the sorting layer of the dropdown list somewhere? It should inherit the value from the parent canvas.
I have the same problem but I made a simple workaround that only checks and updates the sorting layer whenever the Dropdown List template is spawned.
Note:
Put this script on the Template game object inside the Dropdown. You need to change the value of _SortingLayerName to the SortingLayer of the parent canvas where your Dropdown resides.
public class DropdownWorkaround : MonoBehaviour
{
public string _SortingLayerName = “Default”;
I solved this problem just setting the ‘Default’ Sorting Layer in front of all the others (i.e., at the bottom of the Sorting Layer list). Since I avoid to use the ‘Default’ Sorting Layer in my game objects, this change not cause any problem.
Adding to this, I actually added a Canvas to the Template, checked Override Sorting, and set the Sorting Layer to the layer that you want the dropdown list to be on.
This fixed the problem for me, after an hour of pulling my hair out. Thank you! (Unity 5.5.4 on macOS. Yes, afraid to update until I have a few weeks to make sure everything works on 2017.X.)
at version 2019.4 add canvas on Template not work ,
i take a toggle in DropDown and listening the value to set DropDown Show or Hide ,
when show get canvas component and set sorting Layer
Just would like to add that in Unity 2021.2, if you manually add the Canvas to the the “Template” GameObject and set the layer you want it to use, Unity will override all values on play. So it seems that the solution proposed by bdandre_mbiance above which apparently used to work as far as November 2020, does not work anymore.
In TMP_Dropdown.cs change 666 line to sorting number you whant, then in 779 line change to this:
m_Template.GetComponent().sortingLayerID = SortingLayer.NameToID(“Your TargetLayer”);