Search Unity

dropdown not showing dynamic int option

Discussion in 'UI Toolkit' started by PornstacheMcgrath, Sep 21, 2019.

  1. PornstacheMcgrath

    PornstacheMcgrath

    Joined:
    Sep 19, 2019
    Posts:
    4
    Please help
    I have created a method that takes in an int and runs another method. I attached the script to a game object and attached that Game object to the OnValueChanged section of the drop down object in the inspector. However, in the inspector, I am not given the ability to make my method be used as a dynamic int. I've looked and i cant find anyone who's had a similar issue to mine, and because I am new to unity i am unsure as to how to fix this.
    Code (CSharp):
    1. public class CameraMenu : MonoBehaviour
    2. {
    3. public void CameraPosition(int option)
    4.     {
    5.         if (option == 0)
    6.         {
    7.             fixedcamera();
    8.         }
    9.         else if (option == 1)
    10.         {
    11.             floatingcamera();
    12.         }
    13.         else if (option == 2)
    14.         {
    15.             beziercamera();
    16.         }
    17.     }
    18. }
    my script basically looks like this, when i select any of the options from the dropdown it always runs option zero so from what i can tell it only passes 0.
     
  2. PornstacheMcgrath

    PornstacheMcgrath

    Joined:
    Sep 19, 2019
    Posts:
    4
    I forgot to mention it but from what i can tell all the methods that this method is calling do work, it just always runs a 0 case. when i switch which method is assign to option zero around, that case works but only that method. is there a way to make it so each dropdown option sends an int without using dynamic int as an alternative?
     
  3. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    So I just had the same problem. I believe it might be related to the new update, at least that's what it seems for me. Did you recently upgrade to 2019.2.6f1. I upgraded today and this became a problem. I just downgraded back to 2019.2.4f1 and it solved the problem - the dynamic int works again.
     
  4. PornstacheMcgrath

    PornstacheMcgrath

    Joined:
    Sep 19, 2019
    Posts:
    4
    I am in 2019.2.5f1 and ill try to revert it.
     
  5. PornstacheMcgrath

    PornstacheMcgrath

    Joined:
    Sep 19, 2019
    Posts:
    4
    I'm wondering if its a bug cause reverting it didnt really change anything. tomorrow ill try going to an even later build and see if it works there
     
    Last edited: Sep 21, 2019
  6. GSanLob

    GSanLob

    Joined:
    Oct 11, 2017
    Posts:
    14
    Hey, yea I think its definitely a bug. Reverting to 2019.2.4f1 solved the issue for me only in the sense that I figured the bug was in 2.5f1 or 2.6f1 and I backtracked for the moment to avoid it. Sorry that it didn't work for you. Hopefully a fix will come soon.
     
  7. SharksInteractive

    SharksInteractive

    Joined:
    Jan 27, 2018
    Posts:
    17
    Sorry to revive this thread, but I wanted to answer it for anyone else who may come along. Dynamic ints are not a thing. It has to be a float, you can use

    Code (CSharp):
    1. public void SliderFunction (float dynamicFloat)
    2. {
    3.     Mathf.RoundToInt(dynamicFloat);
    4. }
    To convert it to an integer. It seems GSanLob was able to get ints working, I'm going to assume this was a float and he didn't realize it because as far as I know dynamic ints are not a thing, I think it has something to do with sliders returning floats, even when the 'whole numbers' option is ticked. I had the same issue, changed my int to a float and everything worked, so I'm assuming this is the answer. If anyone has more info I'd love to hear!

    Also, in the words of the documentation:
    " The slider has a single event called On Value Changed that responds as the user drags the handle. The current numeric value of the slider is passed to the function as a float parameter. "
     
    rbitard likes this.
  8. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    197
    Now you can use a method with an int signature but it's called with the index of your drop down