(Cross-Posted) Enums as Drop-Downs in Inspector

I am aware this topic has been covered, but unless I’m missing something, I have covered all the bases my predecessors recommend.

I have an audio manager that creates an array of sounds via the inspector. Originally I was using strings as identifiers, but it looked ugly so I decided to switch to an enum since it is a small project and I wiill only be using about twenty sounds. Problem is, when I go into the inspector now, there is only the string value, no drop-down selection as an enum would normally make. Here is my code –

[System.Serializable]
public enum Sounds
{
    TractorBeamStarting,
    TractorBeamRunning,
    TractorBeamStopping,
    Engine,
    HurtMoo_1,
    HurtMoo_2,
    Moo_1,
    Moo_2,
    Moo_3,
    Moo_4,
    Ambience
}
using UnityEngine.Audio;
using UnityEngine;


[System.Serializable]
public class Sound
{
    public string name;

    [SerializeField]
    public Sounds nameEnum;

    [HideInInspector]
    public GameObject soundBoat;

    public AudioClip clip;

    [Range(0f, 1f)]
    public float volume;
    [Range(.1f, 3f)]
    public float pitch;
    [Range(0, 1)]
    public float spatialBlend;


    [HideInInspector]
    public AudioSource source;

    public bool loop;
}
using UnityEngine.Audio;
using System;
using UnityEngine;

public class AudioManager : MonoBehaviour
{
    public Sound[] sounds;
    public static AudioManager instance;

    // Start is called before the first frame update
    void Awake()
    {
        if(instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }

        DontDestroyOnLoad(gameObject);

        foreach (Sound s in sounds)
        {
            GameObject go = Instantiate<GameObject>(new GameObject(s.nameEnum + "_soundBoat", typeof(AudioSource)), gameObject.transform);
            s.soundBoat = go;
            s.source = go.GetComponent<AudioSource>();
            s.source.clip = s.clip;
            s.source.volume = s.volume;
            s.source.pitch = s.pitch;
            s.source.spatialBlend = s.spatialBlend;
            s.source.loop = s.loop;
        }
    }

    public void Play(Sounds name, Vector3 position)
    {
        Sound s = Array.Find(sounds, sound => sound.nameEnum == name);
        if (s == null)
        {
            Debug.LogWarning("Sound: " + name.ToString() + "does not exist!");
            return;
        }
        s.soundBoat.transform.position = position;
        s.source.Play();
    }

    public void PlayOneShot(Sounds name, AudioClip singleUseClip, Vector3 position)
    {
        Sound s = Array.Find(sounds, sound => sound.nameEnum == name);
        if (s == null)
        {
            Debug.LogWarning("Sound: " + name.ToString() + "does not exist!");
            return;
        }
        s.soundBoat.transform.position = position;
        s.source.PlayOneShot(singleUseClip);
    }

    public void Stop(Sounds name)
    {
        Sound s = Array.Find(sounds, sound => sound.nameEnum == name);
        if (s == null)
        {
            Debug.LogWarning("Sound: " + name.ToString() + "does not exist!");
            return;
        }
        s.source.Stop();
    }

    public bool isPlaying(Sounds name)
    {
        Sound s = Array.Find(sounds, sound => sound.nameEnum == name);
        if (s == null)
        {
            Debug.LogWarning("Sound: " + name.ToString() + " does not exist!");
            return false;
        }
        bool _isplaying = s.source.isPlaying;
        return _isplaying;
    }

    public void ChangePitch(Sounds name, float newPitch)
    {
        Sound s = Array.Find(sounds, sound => sound.nameEnum == name);
        if (s == null)
        {
            Debug.LogWarning("Sound: " + name.ToString() + " does not exist!");
            return;
        }
        s.source.pitch = newPitch;
    }

    public Sound GetSound(Sounds name)
    {
        Sound s = Array.Find(sounds, sound => sound.nameEnum == name);
        if (s == null)
        {
            Debug.LogWarning("Sound: " + name.ToString() + " does not exist!");
            return null;
        }
        return s;
    }
}

So I made the enum, then I declare a reference to it, I even made it serializable (both the class and the field), and I’ve got nothing…

Any suggestions?

I just copied your 3 types into me test project and this is what I get:

7992282--1027041--AudioManager.png

So it does work as it should. Are you sure that you don’t have a custom property drawer in your project for your enum type? I would also highly recommend to choose a more descriptive name for your enum type. Note that you should use singular names for types. Only use the plural for array or list fields. In the end a single “Sounds” value represents a single soundtype.

No custom property drawers, I haven’t even begun to learn custom editor scripting, so I def wouldn’t try that.

I have an enum named Sounds because it is a list of all the sounds, then a singleton named “Sound” that holds all the data for a single sound. Each sound gets its own data class (was thinking of scriptable objects here but that’s another field in which I haven’t really done much studying) so it was just a name issue. I get what you’re saying though it looks better to say Sound.Explosion than “Sounds”.

But yeah, no errors in the console, and no enum showing up for me. I even upgraded my unity version…

Have you tried opening the scene file which contains your AudioManager in a text editor? Is the “nameEnum” value actually serialized? Here’s how my test object looks like. As you can see this is the GameObject with the name “AudioManager” and it has two components, the Transform component and the AudioManager component. As you can see each Sound instance does have a nameEnum value (serialized as the underlying int value).

I copied the project and opened the copy, works fine now… I am not sure at all what was going on there.