Can't Return a Value for Drop Down List

There are two ways you can attach this service routine to your DropDown (or Slider): one is very useful, the other is not useful and will return a static number (like 0) and force you to go get the value yourself.

This is how to properly choose the “useful” way. Let’s say you are servicing this Dropdown with this script:

using UnityEngine;

public class DropDownService : MonoBehaviour
{
    public void HandleInput(int val)
    {
        Debug.Log( "Dropdown:" + val);
    }
}

When you drag that script onto a GameObject, then drag the GameObject (NOT THE SCRIPT) onto the Dropdown’s event box, make sure you connect it to the Dynamic callbacks, NOT to the Static callbacks, like so:

ALSO: Beware of this gotcha:

2 Likes