Search Unity

Question How can I get the string of the value of a SerializedProperty?

Discussion in 'Editor & General Support' started by ftejada, Jan 23, 2022.

  1. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hi all!!
    Can you get the name(string) of the value of a SerializedProperty?
    That is, I don't want the name of the SerializedProperty variable... I need to get the value of that variable in string.

    for example, I have a variable of type enum called Features{Fog, Rain, etc}":
    Code (CSharp):
    1. public Features e_feature;
    In the customInspector I get this variable:
    Code (CSharp):
    1. m_e_feature = serializedObject.FindProperty("e_feature");
    And when the time comes, I need to access from m_e_feature the string of the value it contains... that is, the string of the flags {Fog, Lluvia, etc}

    using the api functions "serializedProperty.displayName, serializedProperty.name, serializedProperty.ToString()" I can only get the string "e_feature", but I can't access the value string...

    Any idea how to do it?

    Greetings
    caracteristica
     
    Last edited: Feb 2, 2022
  2. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Any help or information to know if it can be done or not?...

    Greetings
     
  3. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    I've kept searching the internet but I can't find anything that helps me... or at least, something that tells me if it's possible to do what I want.

    Is it possible to access the string value of an enum via SerializedProperty?
    I'm starting to think it's just not possible.

    Any help or information?

    Greetings
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,925
    Never used this part of editor coding (I do it all with Odin), but looking at the documentation I can see three properties that might of interest to you, enumDisplayNames, enumNames and enumValueIndex.

    I think you're always going to need to get the actual value out of a serialised property in order to gleam the information you need.
     
    ftejada likes this.