Search Unity

Support for passing enum as event message method property

Discussion in 'UGUI & TextMesh Pro' started by DXRasm, Dec 30, 2014.

  1. DXRasm

    DXRasm

    Joined:
    Dec 30, 2014
    Posts:
    1
    I'm using the built-in event messaging system to make method calls on my MonoBehaviour and I noticed there isn't support for passing an enum (only bool,int,string,float,object).

    What I'd like:
    Code (CSharp):
    1. public enum MyEnum
    2. {
    3.     Foo,
    4.     Bar,
    5.     Baz
    6. }
    7.  
    8. public void OnButtonClick(MyEnum value)
    9. {
    10.     // Do logic with value
    11. }
    In the editor I would just select from the dropdown the readable enum name I want to send for that button.


    What I have to do instead:
    Code (CSharp):
    1. public void OnButtonClick(int enumCode)
    2. {
    3.     MyEnum value = (MyEnum)enumCode;
    4.     // Do logic with value
    5. }
    In the editor I have to send the proper integer value of the enum which has a lot of room for error and requires you to look up in code what is valid.

    Can this feature be added or is there a better way?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can always wrap your enum as an object.
     
  3. ryanmillerca

    ryanmillerca

    Joined:
    Aug 12, 2012
    Posts:
    143
    Having the same annoying issue myself. Hopefully we see this feature in the future.

    My workaround was to put a script on the button itself with an enum inspector property, point that script where the button would go, and have the button call it's own script.
     
  4. taxvi

    taxvi

    Joined:
    Feb 18, 2013
    Posts:
    30
    same problem here :/
     
    kico1603 and DonPuno like this.
  5. StrongCube

    StrongCube

    Joined:
    Nov 22, 2016
    Posts:
    50
    2018 year... :(
     
    kico1603 and DonPuno like this.
  6. kourosh-ghahremani

    kourosh-ghahremani

    Joined:
    Mar 4, 2019
    Posts:
    1
    2019 phew... :(
     
    kico1603 and DonPuno like this.
  7. PicO_LinO

    PicO_LinO

    Joined:
    Jan 19, 2020
    Posts:
    1
    2020 here...
     
    kico1603, DonPuno, Hades714 and 2 others like this.
  8. dieguezguille

    dieguezguille

    Joined:
    Mar 14, 2019
    Posts:
    2
    2021...
     
    kico1603 and DonPuno like this.
  9. DonPuno

    DonPuno

    Joined:
    Dec 22, 2020
    Posts:
    57
    2022...
     
    kico1603 likes this.
  10. kico1603

    kico1603

    Joined:
    Mar 9, 2018
    Posts:
    1
    2023...
     
    DonPuno likes this.
  11. kwabbott99

    kwabbott99

    Joined:
    Dec 10, 2014
    Posts:
    1
    2024...
     
    DonPuno likes this.