Dropdown list appears behind everything... (598681)

Hi,

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.

Any ideas? Thanks!! :slight_smile:

Ali

4 Likes

UI image sorting is based on position in hierarchy. Try moving your dropdown list up higher in the hierarchy.

1 Like

I have the same problem :face_with_spiral_eyes:. Any solutions to this?

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.

Thanks

1 Like

I made this lame workaround but I think it should be fixed to inherit the canvas value from the parent

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;

public class DropdownCanvasLayer : MonoBehaviour {

    public string SortLayerName;
    public EventSystem eventSystem;
   
    public void Update(){

        if (Input.GetMouseButtonDown (0)) {

            if (eventSystem.IsPointerOverGameObject() && eventSystem.currentSelectedGameObject.name == "Dropdown"){

                StartCoroutine(findList());
            }
        }

    }

    IEnumerator findList(){

        yield return new WaitForSeconds (0.2f);
        GameObject droplist = GameObject.Find ("Dropdown List");
        GameObject blocker = GameObject.Find ("Blocker");

        if (droplist != null) {
           
            droplist.GetComponent<Canvas> ().sortingLayerName = SortLayerName;
            blocker.GetComponent<Canvas> ().sortingLayerName = SortLayerName;
        }
    }

}

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”;

void Awake()
{
Canvas canvas = GetComponent();
if (canvas != null)
canvas.sortingLayerName = _SortingLayerName;
}
}

6 Likes

Hi everyone,

I just find out that if you add a Canvas to your Template game object of your Dropdowns with the wanted sorting layer it works like a charm!

11 Likes

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.

1 Like

Perfect thanks :slight_smile:

1 Like

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.

5 Likes

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.)

After lots of research you’ve just saved my sanity, thanks! :smile:

Perfect, you saved my life.

Canvas popupCanvas = GetOrAddComponent<Canvas>(templateGo);
 popupCanvas.overrideSorting = true;
 popupCanvas.sortingOrder = 30000;

The DropDown’s source code added a canvas whose sortingorder is 30000.

One solution is like Jinxology’s said.However, I prefer to change the source code and customize my own dropdown.

Perfect, thanks

There is a Template gameobject in dropdown object, add a raycaster on that and set the sort order.

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

1 Like

I’m going to move this to the UI forums because the 2D forum is not for UI related questions.

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.

3 Likes

Solution for new version:

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”);

    public class DropdownList : MonoBehaviour
    {
        [SerializeField]
        private Canvas canvas;

        private void OnEnable()
        {
            canvas.sortingLayerName = "Your own layer";
        }
    }

attach it onto “Template” and it should work

1 Like